Ios 检测通过Info.plist中配置的UIBackgroundModes启用的推送通知

Ios 检测通过Info.plist中配置的UIBackgroundModes启用的推送通知,ios,objective-c,notifications,apple-push-notifications,Ios,Objective C,Notifications,Apple Push Notifications,这是我的问题: 我实现了这段代码,用于检测用户是否启用了推送通知 if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) { NSLog(@"Yes, s(he) accepted Push Notification"); } else { NSLog(@"No, s(he) rejected Push Notification"); } 这很有效。但是我必须实现在后台接收静默推送通知,所以

这是我的问题:

我实现了这段代码,用于检测用户是否启用了推送通知

if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
  NSLog(@"Yes, s(he) accepted Push Notification");
} else {
  NSLog(@"No, s(he) rejected Push Notification");
}
这很有效。但是我必须实现在后台接收静默推送通知,所以我在我的
Info.plist

<key>UIBackgroundModes</key>
<array>
  <string>remote-notification</string>
</array>
ui背景模式
远程通知

然后,当我添加这个时,检测用户是否启用推送通知的代码总是返回TRUE,不管用户是否启用推送通知。只有当用户启用可视推送通知(手机顶部的警报)时,才可以检测到允许UIBackgroundModes?

的[[UIApplication sharedApplication]isRegisteredForRemoteNotifications]无法正确使用。要了解用户关于推送通知的决定,需要 currentUserNotificationSettings

UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];

if (!notificationSettings || (notificationSettings.types == UIUserNotificationTypeNone)) {
      isEnabled = NO;
} else {
      isEnabled = YES;
}

它可能的重复是不一样的,因为它在一般情况下引用,但进入注释是解决方案。。。谢谢@dan