測試過程中,發現有以下的錯誤訊息:
registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.
這時候才發現 iOS8 下的推播改版了,改成所謂的互動式推播,即接收推播後,在推播的項目即可直接回覆、動作,不用進入 app 才能動作了;另外,在設定方面也不太一樣了,在 iOS7 下是「設定」>「通知中心」>「應用程式」去設定是否開關通知的設定,現在「設定」下即會有該應用程式,點入應用程式以進入推播設定,如下圖,左邊是 iOS7 例子,右邊是 iOS8 的例子。
前面講的 registerForRemoteNotificationTypes 問題,則要用以下這段程式碼來支援 iOS8 的推播啟始註冊
// Set Notification
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
然後,以下原本在 iOS7 可以用在判斷是否推播有打開的程式
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
return (types & UIRemoteNotificationTypeAlert);
會出現以下的錯誤訊息,不一定會當掉,但功能至少會被忽略.
enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.
這段要改由 currentUserNotificationSettings 去取得 types,所以這段程式碼要用以下這段取代.
UIRemoteNotificationType types;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;
else
types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
return (types & UIRemoteNotificationTypeAlert);
Orignal From: iOS8 下 Push Notification 推播服務的改變