類似的問題在這裏問: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")
}
看起來像工作!非常感謝! –