標籤:
項目要添加推播通知,測試完本地通知後,發現測不了遠程通知。於是想重設授權請求。
以下是重設授權請求的方法:
方法一:
通用->還原->抹掉所有內容和設定
但是第一種方法很費時,抹掉內容估計得幾十分鐘。於是有了第二種方法。
方法二:
將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
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
關於重設IOS App請求推送的授權請求