1

Some of the users of my app are still using iOS7. For iOS 8 and above i simply use:

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

or:

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

But what do I use to check if Notifications are enabled but for iOS7 ?

Thanks in advance!

Tung Fam
  • 7,899
  • 4
  • 56
  • 63

1 Answers1

0

A similar question was asked here: Push Notification ON or OFF Checking in iOS (in 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:

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")
}
Community
  • 1
  • 1