Forked from takecian/PushNotificationManager.swift
Created
November 13, 2015 13:45
-
-
Save loplopLover/0c8e7c5e1efd56b7a256 to your computer and use it in GitHub Desktop.
Utility functions for iOS PushNotification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PushNotificationManager { | |
class var isPushNotificationEnable: Bool { | |
let osVersion = UIDevice.currentDevice().systemVersion | |
if osVersion < "8.0" { | |
let types = UIApplication.sharedApplication().enabledRemoteNotificationTypes() | |
if types == UIRemoteNotificationType.None { | |
// push notification disabled | |
return false | |
}else{ | |
// push notification enable | |
return true | |
} | |
}else{ | |
if UIApplication.sharedApplication().isRegisteredForRemoteNotifications() { | |
// push notification enable | |
return true | |
}else{ | |
// push notification disabled | |
return false | |
} | |
} | |
} | |
class func requestPushNotification() { | |
let application = UIApplication.sharedApplication() | |
let osVersion = UIDevice.currentDevice().systemVersion | |
if osVersion < "8.0" { | |
application.registerForRemoteNotificationTypes(UIRemoteNotificationType.Badge | | |
UIRemoteNotificationType.Sound | | |
UIRemoteNotificationType.Alert ) | |
}else{ | |
var types: UIUserNotificationType = UIUserNotificationType.Badge | | |
UIUserNotificationType.Alert | | |
UIUserNotificationType.Sound | |
var settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil ) | |
application.registerUserNotificationSettings(settings) | |
application.registerForRemoteNotifications() | |
} | |
} | |
class func openAppSettingPage() -> Void { | |
let application = UIApplication.sharedApplication() | |
let osVersion = UIDevice.currentDevice().systemVersion | |
if osVersion < "8.0" { | |
// not supported | |
}else{ | |
let url = NSURL(string:UIApplicationOpenSettingsURLString)! | |
UIApplication.sharedApplication().openURL(url) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment