【问题标题】:Check if push notifications are enabled on iOS7检查是否在 iOS7 上启用了推送通知
【发布时间】:2016-12-01 17:31:04
【问题描述】:

我的应用程序的一些用户仍在使用 iOS7。 对于 iOS 8 及更高版本,我只需使用:

UIApplication.sharedApplication().currentUserNotificationSettings()!.types

或:

UIApplication.respondsToSelector(#selector(UIApplication.isRegisteredForRemoteNotifications))

但是,除了 iOS7 之外,我用什么来检查通知是否已启用?

提前致谢!

【问题讨论】:

    标签: ios swift ios7 xcode7


    【解决方案1】:

    这里问了一个类似的问题:Push Notification ON or OFF Checking in iOS (in obj-c)

    我为你把它转换成swift:

    //if iOS 7
    var types: UIRemoteNotificationType = UIApplication.sharedApplication().enabledRemoteNotificationTypes()
    if types != .None 
    {
        print(" Push Notification ON")
    } 
    

    编辑:您还可以通过执行以下操作来检查正在使用的 ios:

    var iOSversion: String = UIDevice.currentDevice().systemVersion()
    var prefix: String = iOSversion.componentsSeparatedByString(".").first!
    var versionVal: Float = CFloat(prefix)!
    
    if versionVal >= 8 {
        if UIApplication.sharedApplication().currentUserNotificationSettings().types != .None {
             print(" Push Notification ON")
        }
        else {
             var msg: String = "Please press ON to enable Push Notification"
             var alert_push: UIAlertView = UIAlertView(title: "Push Notification Service Disable", message: msg, delegate: self, cancelButtonTitle: "Cancel", otherButtonTitles: "Setting")
             alert_push.tag = 2
             alert_push.show()
             print(" Push Notification OFF")
        }
    }
    
    else {
       var types: UIRemoteNotificationType = UIApplication.sharedApplication().enabledRemoteNotificationTypes()
       if types != .None {
           print(" Push Notification ON")
       }
       else {
          var msg: String = "Please press ON to enable Push Notification"
          var alert_push: UIAlertView = UIAlertView(title: "Push Notification Service Disable", message: msg, delegate: self, cancelButtonTitle: "Cancel", otherButtonTitles: "Setting")
          alert_push.tag = 2
          alert_push.show()
          print(" Push Notification OFF")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多