Episode #256
watchOS Notifications - Part 1
Series: Up to Speed with watchOS

Episode #256
This week's guest author is Dory Glauberman. Dory works for Mutual Mobile in Austin, TX. You can find Dory on Twitter.
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
if granted {
let category = UNNotificationCategory(identifier: "BeerButtonOrderDelivery", actions: [], intentIdentifiers: [], options: [])
center.setNotificationCategories(Set([category]))
} else {
print("No permission" + error.debugDescription)
}
}
let center = UNUserNotificationCenter.current()
center.delegate = self
center.getNotificationSettings { (settings) in
if settings.authorizationStatus == .notDetermined {
// user has not seen apple notification authorization prompt
}
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// this shows the notification, alternatively you could change app state based on the notification or ignore the notification
completionHandler([.alert, .sound])
}
This episode uses Watchos 3, Xcode 8.2.