2016-07-27 33 views
1

我的應用程序的某些用戶仍在使用iOS7。 對於iOS 8.0及以上我簡單地使用:檢查是否在iOS7上啓用了推送通知

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

或:

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

但是,我用它來檢查是否啓用通知,但爲iOS7?

在此先感謝!

回答

0

類似的問題在這裏問:Push Notification ON or OFF Checking in iOS(在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") 
} 
+0

看起來像工作!非常感謝! –

相關問題