Last active
October 17, 2016 13:01
-
-
Save flaviodsilverio/cb8f92ea879c92c5357f7b6079db5e8d to your computer and use it in GitHub Desktop.
This file contains 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
func registerForPushNotifications(application: UIApplication) { // just call this on idFinishLaunchingWith options | |
let notificationSettings = UIUserNotificationSettings( | |
types: [.badge, .sound, .alert], categories: nil) | |
application.registerUserNotificationSettings(notificationSettings) | |
} | |
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { | |
if notificationSettings.types != .none { | |
application.registerForRemoteNotifications() | |
} | |
} | |
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | |
let token = deviceToken.hexString() | |
print(token) | |
} | |
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { | |
print("Failed to Register for remote notifications") | |
} | |
extension Data { | |
func hexString() -> String { | |
return self.reduce("") { string, byte in | |
string + String(format: "%02X", byte) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment