这是我的问题:
我为检测到的用户启用了或不启用推送通知
实现了此代码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?
答案 0 :(得分:0)
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]是否正确使用。要了解用户关于推送通知的决定,请参阅 的 currentUserNotificationSettings 强>
UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (!notificationSettings || (notificationSettings.types == UIUserNotificationTypeNone)) {
isEnabled = NO;
} else {
isEnabled = YES;
}