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