Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本経済新聞社

6 594 vues

Publié le

What's New in UserNotifications Framework

Publié dans : Logiciels
  • Soyez le premier à commenter

What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本経済新聞社

  1. 1. What’s New in User Notifications Framework Masayuki Ono WWDC16. Meetup @Wantedly with
  2. 2. Notifications Sessions, WWDC 2016 Session 707: Introduction to Notifications Session 708: Advanced Notifications (Session 724: What's New in the Apple Push Notification Service) tvOS: Session 206: What's New in tvOS watchOS: Session 211: Quick Interaction Techniques for watchOS
  3. 3. User Notifications framework Single Notification API (UserNotifications Framework) • Across platforms (iOS, watchOS, tvOS) • For local and remote notifications Local notifications improvement Notification management In-app presentation option Notification Extensions • Media attachments • Custom UI
  4. 4. User Notifications framework Single Notification API (UserNotifications Framework) • Across platforms (iOS, watchOS, tvOS) • For local and remote notifications Local notifications improvement Notification management In-app presentation option Notification Extensions • Media attachments • Custom UI
  5. 5. - Existing support for forwarded notifications - Local Notifications on the watch - Support to badge app icons Single Notification API across platforms
  6. 6. iOS Notifications API History API Feature Image iOS 7 UIKit (registerForRemoteNotificationTypes:, etc.) - Visual alert - App icon badging - Sound and vibration - Background/Silent notification (iOS 7) iOS 8/9 UIKit
 (registerUserNotificationSettings:, registerForRemoteNotifications, etc.) - Notification Actions (iOS 8) - Text Input Action(iOS 9) iOS 10 UserNotifications(UI) - Local notifications improvement - Notification management - In-app presentation option - Notification Extensions
  7. 7. Local Notifications Remote Notifications Different APIs & callbacks UserNotifications Framework
  8. 8. Local Notifications UNTimeIntervalNotificationTrigger UNCalendarNotificationTrigger UNLocationNotificationTrigger
  9. 9. Local Notifications // Create content let content = UNMutableNotificationContent() content.title = "title" content.body = "body" content.sound = UNNotificationSound.default() // Create trigger let trigger = UNTimeIntervalNotificationTrigger(timeInterval:5, repeats: false) let identifier = "time_interval_(NSDate())" // Create request with content and trigger let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger) // Add to notification center let center = UNUserNotificationCenter.current() center.add(request) { error in print("error: (error)") }
  10. 10. Notification Handling extension AppDelegate: UNUserNotificationCenterDelegate { // Called when the application is opened by notification func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) { completionHandler() } // Called when the application is in foreground func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { } }
  11. 11. Notification Handling extension AppDelegate: UNUserNotificationCenterDelegate { // Called when the application is opened by notification func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) { completionHandler() } // Called when the application is in foreground func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { } }
  12. 12. Notification Handling extension AppDelegate: UNUserNotificationCenterDelegate { // Called when the application is opened by notification func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) { completionHandler() } // Called when the application is in foreground func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { } }
  13. 13. Notification Handling extension AppDelegate: UNUserNotificationCenterDelegate { // Called when the application is in foreground func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { if let trigger = notification.request.trigger { switch trigger { case let n as UNPushNotificationTrigger: print("UNPushNotificationTrigger: (n)") case let n as UNTimeIntervalNotificationTrigger: print("UNTimeIntervalNotificationTrigger: (n)") case let n as UNCalendarNotificationTrigger: print("UNCalendarNotificationTrigger: (n)") case let n as UNLocationNotificationTrigger: print("UNLocationNotificationTrigger: (n)") default: assert(false) break } } } Trigger
  14. 14. In-app presentation option extension AppDelegate: UNUserNotificationCenterDelegate { // Called when the application is in foreground func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { } }
  15. 15. In-app presentation option extension AppDelegate: UNUserNotificationCenterDelegate { // Called when the application is in foreground func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { completionHandler([.badge, .alert, .sound]) } }
  16. 16. Notification management Access • Pending Notifications • Delivered Notifications Remove Notifications Update and promote Notifications
  17. 17. Remove delivered notification by identifier Local Notifications Identifier • Set on Notification Request let center = UNUserNotificationCenter.current() center.removeDeliveredNotifications(withIdentifiers: [“SOME_IDENTIFIER"]) Remote Notifications Identifier • HTTP/2 request header: apns-collapse-id
  18. 18. Notification Actions (iOS 8) Button with customizable title (iOS 9) Text input action
  19. 19. Notification Actions
  20. 20. Notification Actions // Configure categories let center = UNUserNotificationCenter.current() center.delegate = self let action = UNNotificationAction(identifier: "reply", title: "Reply", options: []) let category = UNNotificationCategory(identifier: "message”, actions: [action], minimalActions: [action], intentIdentifiers: [], options: []) center.setNotificationCategories([category]) // Specify category let content = UNMutableNotificationContent() content.title = "title" content.body = "body" content.sound = UNNotificationSound.default() content.categoryIdentifier = "message"
  21. 21. // Configure categories let center = UNUserNotificationCenter.current() center.delegate = self let action = UNNotificationAction(identifier: "reply", title: "Reply", options: []) let category = UNNotificationCategory(identifier: "message”, actions: [action], minimalActions: [action], intentIdentifiers: [], options: [.customDismissAction]) center.setNotificationCategories([category]) // Specify category let content = UNMutableNotificationContent() content.title = "title" content.body = "body" content.sound = UNNotificationSound.default() content.categoryIdentifier = "message" Notification Actions
  22. 22. Notification Actions Handling // iOS 8/9 func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, for notification: UILocalNotification, completionHandler: () -> Void) { completionHandler() } // iOS 10: func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () - > Void) { let identifier = response.actionIdentifier completionHandler() }
  23. 23. Notification Service Extension Notification Content Extension
  24. 24. Notification Service Extension Non UI iOS Extension Augment or Replace the content of visible Remote Notifications Extension
  25. 25. Notification Service Extension End-to-end encryption Media Attachments Extension
  26. 26. Media Attachments { aps: { alert: { ... }, mutable-content: 1 } my-attachment: “https://example.com/photo.jpg” }
  27. 27. Notification Service Extension class NotificationService: UNNotificationServiceExtension { var contentHandler: ((UNNotificationContent) -> Void)? var bestAttemptContent: UNMutableNotificationContent? // Called when the notification recieved override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler:(UNNotificationContent) -> Void) { self.contentHandler = contentHandler bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) if let bestAttemptContent = bestAttemptContent { // Modify content bestAttemptContent.title = "(bestAttemptContent.title) [modified]" contentHandler(bestAttemptContent) } } // Called when the extension time will expire override func serviceExtensionTimeWillExpire() { if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { contentHandler(bestAttemptContent) } } }
  28. 28. Notification Service Extension class NotificationService: UNNotificationServiceExtension { var contentHandler: ((UNNotificationContent) -> Void)? var bestAttemptContent: UNMutableNotificationContent? // Called when the notification recieved override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler:(UNNotificationContent) -> Void) { self.contentHandler = contentHandler bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) if let bestAttemptContent = bestAttemptContent { // Modify content bestAttemptContent.title = "(bestAttemptContent.title) [modified]" contentHandler(bestAttemptContent) } } // Called when the extension time will expire override func serviceExtensionTimeWillExpire() { if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { contentHandler(bestAttemptContent) } } }
  29. 29. Notification Content Extension
  30. 30. Notification Content Extension class NotificationViewController: UIViewController, UNNotificationContentExtension { @IBOutlet var label: UILabel! override func viewDidLoad() { super.viewDidLoad() } func didReceive(_ notification: UNNotification) { self.label.text = notification.request.content.body } }
  31. 31. 84% of devices are using iOS 9. (May 9, 2016) https://developer.apple.com/support/app-store/ Problem: Fragmentation
  32. 32. iOS Notifications API History API Feature Image iOS 7 UIKit (registerForRemoteNotificationTypes:, etc.) - Visual alert - App icon badging - Sound and vibration - Background/Silent notification (iOS 7) iOS 8/9 UIKit
 (registerUserNotificationSettings:, registerForRemoteNotifications, etc.) - Notification Actions (iOS 8) - Text Input Action(iOS 9) iOS 10 UserNotifications(UI) - Local notifications improvement - Notification management - In-app presentation option - Notification Extensions
  33. 33. How to support multiple iOS versions? Ignore new UserNotifications APIs • No code changes are required? Wrapper LIbraries • https://github.com/square/SuperDelegate
  34. 34. APNs Payload Format { "aps": { "alert": { "title": “Introduction to Notifications", "subtitle": “Session 707", "body": "Woah! These new notifications look amazing! Don’t you agree?" }, "badge": 1 } } iOS 10 Title Subtitle Body
  35. 35. Links WWDC • Session 707: Introduction to Notifications • Session 708: Advanced Notifications • Session 724: What's New in the Apple Push Notification Service • Session 206: What's New in tvOS (tvOS) • Session 211: Quick Interaction Techniques for watchOS (watchOS) Reference • UserNotificaitons • UserNotificationsUI • UNNotificationServiceExtension • UNNotificationContentExtension Articles • iOS User Notifications framework | | Developers.IO

×