Last active
April 5, 2017 14:25
-
-
Save youvalv/3392360ce8aaddefa652af55b79b7527 to your computer and use it in GitHub Desktop.
Register for remote notifications
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
private func registerForRemoteNotifications () { | |
if #available(iOS 10.0, *) { | |
let userNotificationType: UNAuthorizationOptions = [UNAuthorizationOptions.alert, UNAuthorizationOptions.badge, UNAuthorizationOptions.sound] | |
UNUserNotificationCenter.current().setNotificationCategories([self.getNewCategoryByIdentifier(identifier: kMorningEventIdentifier), | |
self.getNewCategoryByIdentifier(identifier: kEveningEventIdentifier), | |
self.getNewCategoryByIdentifier(identifier: kTakePillboxEventIdentifier)]) | |
UNUserNotificationCenter.current().requestAuthorization(options: userNotificationType, completionHandler: { (success:Bool, error:Error?) in | |
}) | |
} else { | |
let userNotificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound] | |
let userNotificationSettings: UIUserNotificationSettings = UIUserNotificationSettings(types: userNotificationTypes, | |
categories: [self.getCategoryByIdentifier(identifier: kMorningEventIdentifier), | |
self.getCategoryByIdentifier(identifier: kEveningEventIdentifier), | |
self.getCategoryByIdentifier(identifier: kTakePillboxEventIdentifier)]) | |
UIApplication.shared.registerUserNotificationSettings(userNotificationSettings) | |
UIApplication.shared.registerForRemoteNotifications() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment