zoukankan      html  css  js  c++  java
  • swift 和 OC 判断用户是否允许接收推送通知

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

                }

            }

            

        }

  • 相关阅读:
    关于java中面向对象特征的总结
    Jemter TCP压测坑:Hex-encoded binary string contains an uneven no. of digits,Hex-encoded binary string contains an uneven no. of digits
    distinct&group by去重的区别
    Idea从gitee上clone项目时候相关问题
    Nginx正向代理
    docker安装MySQL5.7
    Ubuntu server18.04.5环境配置
    Ubuntu18.04.5 server wifi的连接
    git commit 提交规范
    关于js的学习的推介
  • 原文地址:https://www.cnblogs.com/-ios/p/13064251.html
Copyright © 2011-2022 走看看