#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設置已禁用")
}
}
}