在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#pragma mark --------------- 判断用户是否允许接收通知 oc - (BOOL)isUserNotificationEnable { BOOL isEnable = NO; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0f) { // iOS版本 >=8.0 处理逻辑 UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings]; isEnable = (UIUserNotificationTypeNone == setting.types) ? NO : YES; } else { // iOS版本 <8.0 处理逻辑 UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; isEnable = (UIRemoteNotificationTypeNone == type) ? NO : YES; } return isEnable; }
#pragma mark --------------- 判断用户是否允许接收通知 swift func checkPushNotification(){ if #available(iOS 10.0, *) { UNUserNotificationCenter.current().getNotificationSettings(){ (setttings) in
switch setttings.authorizationStatus{ case .authorized: print("enabled notification setting启动") case .denied: print("setting has been disabled禁用") case .notDetermined: print("something vital went wrong here出了问题") case .provisional: print("something vital went wrong here出了问题") @unknown default: print("something vital went wrong here出了问题") } } } else {
let isNotificationEnabled = UIApplication.shared.currentUserNotificationSettings?.types.contains(UIUserNotificationType.alert) if isNotificationEnabled == true{ print("enabled notification setting启动通知设置") }else{ print("setting has been disabled设置已禁用") } }
} |
请发表评论