【发布时间】:2013-03-25 16:37:23
【问题描述】:
我有一个 switch 语句,它利用 nsuserdefaults bool 函数来确定打开和关闭。我的问题是当 switch 键 bool 为 yes 时,如何在视图控制器中调用 appdelegate.m 方法。基本上在 view controller.m 的第一个 if 语句中调用 appdelagte.m 方法。
Appdelegate.m
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
TUPushHelper * helper = [[TUPushHelper alloc] initWithTokenData:devToken];
[helper registerDevice];
}
Viewcontroller.m
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"SwitchKey"]) {
NSLog(@"ok");
}
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"SwitchKey"]) {
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
}
【问题讨论】:
标签: iphone ios objective-c xcode push-notification