1. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Feb 10, 2017
Akifumi Fukaya
Development Dept. 1
IP Platform Div.
DeNA Co., Ltd.
Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Feb 10, 2017
Akifumi Fukaya
Development Dept. 1
IP Platform Div.
DeNA Co., Ltd.
マンガボックス
iOS10プッシュ通知
導入事例
1
2. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
自己紹介
• 深谷 哲史(ふかや あきふみ)
• 2014年度 新卒入社
• IPプラットフォーム事業部開発一部 所属
• マンガボックス
• iOS/Androidエンジニア
2
3. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
背景
• 2016年9月にiOS10がリリース
• マンガボックスでは、新しい技術を積極的に導入しよう
と実装を検討
• iOS10の新機能
• User Notifications
• iMessage App
• Siri Kit
3
4. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
背景
• 2016年9月にiOS10がリリース
• マンガボックスでは、新しい技術を積極的に導入しよう
と実装を検討
• iOS10の新機能
• User Notifications
• iMessage App
• Siri Kit
4
マンガボックスと相性が良さそう!
5. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
iOS10の通知
Advanced Notifications - WWDC 2016より引用
https://developer.apple.com/videos/play/wwdc2016/708/
5
6. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
WWDC 2016 ビデオ
https://developer.apple.com/videos/play/wwdc2016/707/
https://developer.apple.com/videos/play/wwdc2016/708/
6
7. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
マンガボックスでの導入事例
7
8. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
マンガボックスでの導入事例
8
Episode
Notification
Content
Extension
Notification Service
Extension
Comics
Notification
Content
Extension
9. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Notification Service Extensionの導入
• 通知表示前にペイロードを受け取り、表示内容
を操作できる
• アタッチメント画像のダウンロードと表示
• 暗号化文字列の復号化
9
APNs
Payload
Notification Service
Extension
10. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Notification Service Extensionの導入
10
APNs
Payload
Notification Service
Extension
{
"aps": {
"alert": {},
"mutable-content": 1
},
"attachment_image_url": "https://example.com/photo.jpg"
}
11. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Notification Service Extensionの追加
11
12. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
NotificationService.swift
12
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping
(UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent
= (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload
will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
13. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
NotificationService.swift
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping
(UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent
= (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload
will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
14. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Notification Contentの導入
14
15. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Notification Contentの追加
15
16. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
NotificationViewController.swift
import UIKit
import UserNotifications
import UserNotificationsUI
class NotificationViewController: UIViewController, UNNotificationContentExtension {
@IBOutlet var label: UILabel?
override func viewDidLoad() {
super.viewDidLoad()
// Do any required interface initialization here.
}
func didReceive(_ notification: UNNotification) {
self.label?.text = notification.request.content.body
}
}
17. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
MainInterface.storyboard
17
18. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
ハマった点の紹介
• アタッチメント画像がクリッピングされてしまう
• NotificationService#didReceive(_:withContentHandler:) で時間の
かかる処理を実行すると、Extensionの正常終了されてしまう
• mutable-content:1を含むペイロードのプッシュ通知が届かない
端末が出現
• Content Extensionの中身が真っ白
18
19. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
ハマった点の紹介
• アタッチメント画像がクリッピングされてしまう
• NotificationService#didReceive(_:withContentHandler:) で時間の
かかる処理を実行すると、Extensionの正常終了されてしまう
• mutable-content:1を含むペイロードのプッシュ通知が届かない
端末が出現
• Content Extensionの中身が真っ白
19
20. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
アタッチメント画像がクリッピングされてしまう
20
APNs
Payload
Notification Service
Extension
送信元画像 表示画像
クリッピングされてしまう
※ iOS 10.0で検証
21. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
アタッチメント画像がクリッピングされてしまう
let attachment = try UNNotificationAttachment(identifier: "image",
url: path,
options: nil)
bestAttemptContent.attachments = [attachment]
22. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
アタッチメント画像がクリッピングされてしまう
22
23. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
アタッチメント画像がクリッピングされてしまう
23
24. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
アタッチメント画像がクリッピングされてしまう
let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
let dicRep = rect.dictionaryRepresentation
let options =
[UNNotificationAttachmentOptionsThumbnailClippingRectKey:dicRep]
let attachment = try UNNotificationAttachment(identifier: "image",
url: path,
options: options)
bestAttemptContent.attachments = [attachment]
拡大できるが縮小はできない
25. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
アタッチメント画像がクリッピングされてしまう
25
iOS 10.0 iOS 10.2
iOS 10.2で直ってました!
26. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
ハマった点の紹介
• アタッチメント画像がクリッピングされてしまう
• NotificationService#didReceive(_:withContentHandler:) で時
間のかかる処理を実行すると、Extensionの正常終了されてし
まう
• mutable-content:1を含むペイロードのプッシュ通知が届かない
端末が出現
• Content Extensionの中身が真っ白
26
27. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
ハマった点の紹介
• アタッチメント画像がクリッピングされてしまう
• NotificationService#didReceive(_:withContentHandler:) で時間の
かかる処理を実行すると、Extensionの正常終了されてしまう
• mutable-content:1を含むペイロードのプッシュ通知が届かない
端末が出現
• Content Extensionの中身が真っ白
27
28. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
プッシュ通知が届かない端末が出現
28
マンガボックス
iOS10対応版 リリース
v2.9.1 v2.10.0
iOS 9 iOS 10
通知が届かないケース
9/12 9/14
iOS 10リリース
プッシュ通知が届かない!
29. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
プッシュ通知が届かない端末が出現
29
v2.9.1 v2.10.0
iOS 9 iOS 10
9/12 9/14
通知が届くケース
iOS 10リリースマンガボックス
iOS10対応版 リリース
30. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
プッシュ通知が届かない端末が出現
30
v2.9.1 v2.10.0
iOS 9 iOS 10
通知が届かないケース
9/12 9/14 プッシュ通知が届かない!
iOS 9では通知エクステンションが
含まれていないのでは
31. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
プッシュ通知が届かない端末が出現
• 現象
• 届かないケース
• iOS 9で通知エクステンションを含むアプリをインストールし、iOS 10にアップ
デート後、プッシュ通知にmutable-content: 1が含まれる場合
• 届くケース
• iOS 10にOSをアップデート後、エクステンションを含むアプリをインストール
or アップデート
• mutable-content: 1をペイロードから削除
• 考えられる要因
• iOS 9でインストールされるアプリには、通知エクステンションが含ま
れていないのでは
31
32. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
ハマった点の紹介
• アタッチメント画像がクリッピングされてしまう
• NotificationService#didReceive(_:withContentHandler:) で時間の
かかる処理を実行すると、Extensionの正常終了されてしまう
• mutable-content:1を含むペイロードのプッシュ通知が届かない
端末が出現
• Content Extensionの中身が真っ白
32
33. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
プッシュ通知試してください!
33
34. Copyright (C) DeNA Co.,Ltd. All Rights Reserved.Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
ありがとうございました
34