直到今晚晚些时候我才能正确测试这段代码,但为了避免事先出现一些错误,这可以用来打开和关闭通知吗?这NSUserDefault
是来自 switch 语句,应该是不言自明的。注册和注销是否模仿 iOS 设置推送通知开关的功能(打开和关闭通知)?
-(void)notification{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"Switch"]) {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"Switch"]) {
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
}
}