對於iOS> = 8,僅的iOS 8+遠程通知能力始終啓用
以我的AppDelegate,我註冊的用戶通知如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"didFinishLaunchingWithOptions called");
// iOS >= 8.0
// register to receive user notifications
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
...
}
在完成後,我註冊遠程通知作爲如下:
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
NSLog(@"didRegisterUserNotificationSettings called");
//register to receive remote notifications
[application registerForRemoteNotifications];
}
,完成之後,我請檢查應用程序是否已註冊
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken called");
BOOL pushNotificationOnOrOff = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; // always returns TRUE
}
但應用始終表示推送通知被啓用,即使用戶已明確設置應用程序的遠程通知功能關閉(通過通知權限警告該應用程序的第一次安裝後出現,或通過應用程序設置。)
我已將應用程序的背景模式/遠程通知設置爲TRUE。我一直在使用開發證書編譯的實際設備上進行調試(通過USB電纜進行連接)。
幫助,我一直在爲此奮鬥了幾個小時。
只是要評論快速,我觀察到一個應用程序我現在工作的這個相同的行爲,在iPhone 5S 9.2.1運行。當背景刷新關閉時,該值按預期返回true或false。當背景刷新打開時,此值僅返回true。 –