Slide 1

Slide 1 text

Advanced Notification for iOS 10 USAMI Kosuke Fenrir Inc.

Slide 2

Slide 2 text

iOS Notification API

Slide 3

Slide 3 text

Old API ☞ UIApplication ☞ Registering for Notifications ☞ UIApplicationDelegate ☞ Handling Notifications

Slide 4

Slide 4 text

New API (iOS 10) ☞ UserNotifications framework ☞ UserNotificationsUI framework

Slide 5

Slide 5 text

References ☞ WWDC 2016 ☞ Introduction to Notifications ☞ Advanced Notifications ☞ Apple Developer Documentation ☞ UserNotifications ☞ UserNotificationsUI

Slide 6

Slide 6 text

UserNotifications framework

Slide 7

Slide 7 text

Notification Center ☞ UNUserNotificationCenter

Slide 8

Slide 8 text

Request User Authorization ☞ UNUserNotificationCenter ☞ func requestAuthorization(_:completionHandler:)

Slide 9

Slide 9 text

Push Notification ☞ UIApplication ☞ func registerForRemoteNotifications() ☞ (Existing API)

Slide 10

Slide 10 text

Local Notification ☞ UNUserNotificationCenter ☞ func add(_:withCompletionHandler:) ☞ UNNotificationRequest ☞ content ☞ trigger : TimeInterval / Calendar / Location

Slide 11

Slide 11 text

In-App Presentation (New!) // UNUserNotificationCenterDelegate func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { // Show notification in foreground completionHandler([.alert, .sound, .badge]) }

Slide 12

Slide 12 text

Others ☞ Custom Action ☞ Notification Management

Slide 13

Slide 13 text

Advanced Notifications

Slide 14

Slide 14 text

Advanced Notifications (iOS 10) ☞ Media Attachments ☞ Rich Notification (Custom User Interface)

Slide 15

Slide 15 text

Media Attachments

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

For Local Notification ☞ UNNotificationAttachment ☞ url : URL of attachment ☞ type : UTI type

Slide 18

Slide 18 text

For Push Notification

Slide 19

Slide 19 text

Notification Service Extension ☞ UserNotifications framework ☞ UNNotificationServiceExtension

Slide 20

Slide 20 text

Download Attachment ☞ UNNotificationServiceExtension ☞ func didReceive(_:withContentHandler:) ☞ Download in Service extension ☞ Create UNNotificationAttachment

Slide 21

Slide 21 text

Limited Processing Time ☞ UNNotificationServiceExtension ☞ func serviceExtensionTimeWillExpire() ☞ Provide some fallback content

Slide 22

Slide 22 text

Limited File Size ☞ Audio : 5MB ☞ Image : 10MB ☞ Movie : 50MB

Slide 23

Slide 23 text

Rich Notification

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

To Display Rich Notification ☞ 3D Touch on Notification ☞ Swipe Left in Notification List ☞ Swipe Down in Notification Banner

Slide 26

Slide 26 text

Custom User Interface ☞ Custom Views (No interaction) ☞ Media Attachment ☞ Media Playback ☞ Notification Action ☞ Text Input Action

Slide 27

Slide 27 text

Notification Content Extension ☞ UserNotificationsUI framework ☞ UNNotificationContentExtension

Slide 28

Slide 28 text

Custom UI ☞ To change layout ... ☞ In Info.plist ☞ Specify custom views ratio ☞ Show/Hide default contents

Slide 29

Slide 29 text

Custom Views ☞ UNNotificationContentExtension ☞ func didReceive(_:) ☞ Get UNNotification ☞ Display contents to custom views

Slide 30

Slide 30 text

Minimal implementation class NotificationViewController: UIViewController, UNNotificationContentExtension { @IBOutlet weak var label: UILabel! func didReceive(_ notification: UNNotification) { label.text = notification.request.content.body } }

Slide 31

Slide 31 text

Media Attachment class NotificationViewController: UIViewController, UNNotificationContentExtension { func didReceive(_ notification: UNNotification) { let content = notification.request.content let attachment = content.attachments.first // attachment: UNNotificationAttachment // ... } }

Slide 32

Slide 32 text

Media Playback ☞ UNNotificationContentExtension ☞ mediaPlayPauseButtonType ☞ none / default / overlay ☞ mediaPlayPauseButtonFrame / TintColor ☞ func mediaPlay() / func mediaPause()

Slide 33

Slide 33 text

Notification Action

Slide 34

Slide 34 text

Notification Action ☞ UNUserNotificationCenter ☞ Set UNNotificationAction ☞ UNNotificationContentExtension ☞ func didReceive(_:completionHandler:) ☞ Get UNNotificationResponse

Slide 35

Slide 35 text

Text Input Action ☞ UNNotificationAction ☞ → UNTextInputNotificationAction ☞ UNNotificationResponse ☞ → UNTextInputNotificationResponse

Slide 36

Slide 36 text

Summary

Slide 37

Slide 37 text

Summary ☞ New API ☞ UserNotifications / UserNotificationsUI ☞ Notification Service extension ☞ Media Attachments ☞ Notification Content extension ☞ Custom Views / Action