项目要加入推送通知。測试完本地通知后。发现測不了远程通知。于是想重置授权请求。
下面是重置授权请求的方法:
方法一:
通用
->还原
->抹掉全部内容和设置
可是第一种方法非常费时,抹掉内容预计得几十分钟。于是有了另外一种方法。
方法二:
将App从设备上删除
将设备全然关机再又一次启动
打开 设置->通用->日期与时间里 将设备时间拔快一天以上
将设备再次全然关机再又一次启动
此时再安装你的App能够像纯新的流程一样进行測试全部授权。
在设置中查看你的App授权选项也是所有重置。
附上注冊通知的代码:
在AppDelegate的 didFinishLaunchingWithOptions方法中。加入代码:
UIApplication *app = [UIApplication sharedApplication];
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
if ([app respondsToSelector:@selector(registerUserNotificationSettings:)]) {
NSLog(@"8.0注冊通知");
[app registerUserNotificationSettings:settings];
} else {
NSLog(@"7.0及下面 注冊通知");
[app registerForRemoteNotificationTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound];
}
对于IOS8 ,新增了didRegisterUserNotificationSettings方法。
假设要注冊RemoteNotification,须要在此方法里加入注冊代码:
if (IS_IOS8) {
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
否则,假设注冊通知没完毕,就加入
[[UIApplication sharedApplication] registerForRemoteNotifications]
会引起下面warning:
Attempting to schedule a local notification ..... with an alert but haven't received permission from the user to display alerts