且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

始终启用iOS 8+远程通知功能

更新时间:2021-10-02 22:03:32

这似乎是一个错误,我也在iPhone 6,iOS 8.1.2上发现了相同的行为。

This seems to be a bug, I also discovered the same behaviour on iPhone 6, iOS 8.1.2.

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications] 总是返回 TRUE 即使用户拒绝推送通知权限(通过提醒视图)或通过 Settings.app>手动禁用通知通知

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications] always returns TRUE even if user declined the push notification permission (via the alert view) or by manually disabling the notification via Settings.app > Notifications.

经过一些研究后,我发现如果您已启用后台应用刷新对于应用程序,然后 [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] 将始终返回 TRUE

After some research I discovered that if you have Background App Refresh enabled for the app, then [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] will always returns TRUE.

后台应用刷新设置为 FALSE 然后 [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] 返回正确的值。

When Background App Refresh set to FALSE then [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] returns the correct value.

作为解决方法,您可以评估 [[UIApplication sharedApplication] currentUserNotificationSettings] .types 确定是否允许推送通知。

As a workaround, you can evaluate the [[UIApplication sharedApplication] currentUserNotificationSettings].types to determine whether the push notification is allowed or not.

typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
    UIUserNotificationTypeNone    = 0,      // the application may not present any UI upon a notification being received
    UIUserNotificationTypeBadge   = 1 << 0, // the application may badge its icon upon a notification being received
    UIUserNotificationTypeSound   = 1 << 1, // the application may play a sound upon a notification being received
    UIUserNotificationTypeAlert   = 1 << 2, // the application may display an alert upon a notification being received
} NS_ENUM_AVAILABLE_IOS(8_0);

希望这会有所帮助。