[英]Check if push notifications are enabled on iOS7
Some of the users of my app are still using iOS7. 我的应用程序的一些用户仍在使用iOS7。 For iOS 8 and above i simply use:
对于iOS 8及以上版本,我只需使用:
UIApplication.sharedApplication().currentUserNotificationSettings()!.types
or: 要么:
UIApplication.respondsToSelector(#selector(UIApplication.isRegisteredForRemoteNotifications))
But what do I use to check if Notifications are enabled but for iOS7 ? 但是我如何使用它来检查是否启用了通知但是对于iOS7?
Thanks in advance! 提前致谢!
A similar question was asked here: Push Notification ON or OFF Checking in iOS (in obj-c) 这里也提出了类似的问题: 在iOS中推送或关闭推送通知 (在obj-c中)
I converted it to swift for you: 我把它转换成你的快速:
//if iOS 7
var types: UIRemoteNotificationType = UIApplication.sharedApplication().enabledRemoteNotificationTypes()
if types != .None
{
print(" Push Notification ON")
}
EDIT: You can also check which ios is being used by doing the following: 编辑:您还可以通过执行以下操作来检查正在使用的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")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.