1. 程式人生 > >iOS8系統下的無法彈出通知

iOS8系統下的無法彈出通知

<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]];
    }