【问题标题】:Detecting Push Notification enabled with UIBackgroundModes configured in Info.plist使用 Info.plist 中配置的 UIBackgroundModes 检测启用的推送通知
【发布时间】:2016-03-31 16:02:34
【问题描述】:

这是我的问题:

我实现了这个代码来检测用户是否启用了推送通知

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>

然后,当我添加这个时,检测用户是否启用Push notification 的代码总是返回 TRUE,用户是否启用推送通知都没有关系。有什么方法可以检测到用户是否启用了可见推送通知(手机顶部的警报),允许 UIBackgroundModes?

【问题讨论】:

标签: ios objective-c notifications apple-push-notifications


【解决方案1】:

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications] 使用不正确。要知道用户对推送通知的决定是 currentUserNotificationSettings

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

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

【讨论】:

    猜你喜欢
    • 2018-01-08
    • 1970-01-01
    • 2014-12-16
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多