iOS8系統下的無法彈出通知
阿新 • • 發佈:2019-01-03
<span style="font-size: 18px; font-family: Arial; line-height: 26px;">在iOS8系統開發使用本地通知時,通知無法彈出,會出現如下的提示Log:</span>
Attempting to schedule a local notification ,with an alert but haven't received permission from the user to display alerts,with a sound but haven't received permission from the user to play sounds
原因在於iOS8系統變更了註冊方法,需要在ApplicationDelegate裡面註冊通知才可以。
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) { [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; }