美文网首页
Swift 设置里该APP是否开启了推送通知的权限

Swift 设置里该APP是否开启了推送通知的权限

作者: sampson0115 | 来源:发表于2021-10-19 16:37 被阅读0次
    // 通知的认证状态
    func checkPushNotification(){
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().getNotificationSettings(){ (setttings) in
                switch setttings.authorizationStatus{
                case .authorized:
                    print("The application is authorized to post user notifications.")
                case .denied:
                    print("The application is not authorized to post user notifications.")
                case .notDetermined:
                    print("The user has not yet made a choice regarding whether the application may post user notifications.")
                case .provisional:
                    print("The application is authorized to post non-interruptive user notifications.")
                case .ephemeral:
                    print("The application is temporarily authorized to post notifications. Only available to app clips.")
                @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")
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:Swift 设置里该APP是否开启了推送通知的权限

          本文链接:https://www.haomeiwen.com/subject/ktmaoltx.html