如何检查 iPhone 上的通知是否已启用? 我安装了应用程序,应用程序提示确认为应用程序启用推送通知,我点击确定。但是如果 iPhone 上禁用了通知,则此操作不会启用通知。 如何检查?
如何检查 iPhone 上的通知是否已启用? 我安装了应用程序,应用程序提示确认为应用程序启用推送通知,我点击确定。但是如果 iPhone 上禁用了通知,则此操作不会启用通知。 如何检查?
这应该可以工作:
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone)
// Disabled
+ (BOOL)notificationServicesEnabled {
BOOL isEnabled = NO;
if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]){
UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (!notificationSettings || (notificationSettings.types == UIUserNotificationTypeNone)) {
isEnabled = NO;
} else {
isEnabled = YES;
}
} else {
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types & UIRemoteNotificationTypeAlert) {
isEnabled = YES;
} else{
isEnabled = NO;
}
}
return isEnabled;
}
AppDelegate
还是ViewController
中? - SRMRDeviceNotificationsManager
类中,该类封装了与手机通知子系统相关的逻辑。这样外部世界(即应用程序的其余部分)只需引用DeviceNotificationsManager
,而不必详细了解iOS的通知系统。 - Shaheen Ghiassy