在我的应用中,我检查用户是否已启用我的应用通知,启用本地通知,我这样做:
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types != UIRemoteNotificationTypeNone)
{
//All enabled
} else {
//not enabled
}
但是我遇到一些问题,一些用户在iOS设置中都已启用,他们会向我发送屏幕截图,这一切都正确,但代码在else语句中,就好像它全部被禁用一样。 什么是问题,谁知道我怎么能解决它?
由于
答案 0 :(得分:2)
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
UIRemoteNotificationType allEnableType = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge ;
UIRemoteNotificationType disableType = UIRemoteNotificationTypeNone ;
if (types == allEnableType) {
// all enable
} else if (types == disableType) {
// all disable
} else {
// some enable
}
在ios 5.0 UIRemoteNotificationTypeNewsstandContentAvailability
答案 1 :(得分:0)
func isRegisteredForPushNotifications() -> Bool {
if let notificationSettings = application.currentUserNotificationSettings() {
return notificationSettings.types != UIUserNotificationType.None
}
return false
}
我在Swift 2中使用它,在iOS9上测试过。