SlideShare a Scribd company logo
No#fica#ons in iOS10
2016/07/21
@TachibanaKaoru
自己紹介
フリーランスのiOSエンジニアをしていま
す。
(2016年8月から!)
• Twi%er: @TachibanaKaoru
• Blog : h%p://www.toyship.org/
• ボルダリグン好き
What's new in No.fica.on of iOS
• 通知に"tle/sub"tleがつけられるようになった
• 通知にイメージや画像がつけられるようになった
• 通知にCustom UIがつけられるようになった
• ユーザーが通知を許可したかどうかの設定がとれるようになっ
た
• 配信・未配信の通知を簡単にハンドリングできるようになった
配信・未配信の通知を簡単にハンド
リングできるようになった
Local No(fica(onとRemote No(fica(onが統
一されました。
Remote No(fica(on
{
"aps" : {
"alert" : {
"title" : "Introduction to Notifications",
"subtitle" : "Session 707",
"body" : "Woah! These new notifications look amazing!"
},
"badge" : 1 },
}
Local No(fica(on
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Hello"
content.body = "This is a big news!"
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 10, repeats: false)
let request = UNNotificationRequest.init(
identifier: "NewsUpdate", // このIDをキーにして削除や編集をします
content: content,
trigger: trigger)
center.add(request)
通知の管理
まず、通知の状態には下記の3つがあります。
• Pending : まだ発火していない通知
• Delivered : 発火したが、ユーザーが処理(タップなど)をして
いない通知
• (Read) : ユーザーが処理をした通知 (この状態の通知は取得で
きません。)
通知の状態遷移
• 登録された通知は、Pending状態となる
• トリガーイベント(時間や位置など)により発火してDelivered
状態となる
• ユーザーが処理をするとReadとなり、
UNUserNo2fica2onCenterからは取得できなくなる
get pending no*fica*ons
UNUserNotificationCenter.current().getPendingNotificationRequests { requests in
print("== Pending Notification : (requests.count) == ")
for request in requests {
request.identifier
request.content.title
request.content.subtitle
request.content.body
request.trigger
print(" -- title : (request.content.title) body:(request.content.body)")
}
}
delete pending no+fica+ons
//特定のpending通知を消す
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: ["NewsUpdate","NewsDelivery"])
//全部のpending通知を消す
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
update pending no,fica,ons
// 新しいcontentをつくる
let content = UNMutableNotificationContent()
content.title = "Hello"
content.body = "This is a more big news!"
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
// 新しいrequestをつくる
let newRequest = UNNotificationRequest.init(identifier: "NewsUpdate", content: content, trigger: trigger)
// 新しいrequestをつくる(古いものをdeleteする必要はない)
UNUserNotificationCenter.current().add(newRequest) { error in
// error
}
get delivered no,fica,ons
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
// [UNNotification])
print("== Delivred Notification : (notifications.count) == ")
for notification in notifications {
notification.date
notification.request
print(" -- title : (notification.request.content.title) body:(notification.request.content.body) date: (notification.date)")
}
}
delete delivered no+fica+ons
//特定のdeliverされた通知を消す
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: ["NewsUpdate","NewsDelivery"])
//全部のdeliverされた通知を消す
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
No#fica#on in ac#on
• アプリが Foregroundにある状態で通知が配信された場合に、シ
ステムの通知画面をだせるようになりました。
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
print("! Notification came!(notification.request.content.title)")
completionHandler([.alert, .sound])// これをいれておくと、システムの通知画面をだしてくれる
}
iOS9とiOS10の通知ハンドリングの違い
• Fav通知
• iOS9までは、Favされるたびに通知がくるので、通知欄が特
定のtweetのFav通知でうまってしまった
• iOS10では、Favされるたびに通知を更新するため、特定の
tweetのFav通知は常に一つ
iOS9とiOS10の通知ハンドリングの違い
• コメント通知
• iOS9までは、コメントがつくたびに通知を送っていたため、
もりあがっているスレッドのコメント通知でうまってしまっ
た
• iOS10では、コメントがつくたびに通知を更新するため、特
定のスレッドの通知は常に一つ
まとめ
• iOS10では通知の内容を変更することができるようになったた
め、柔軟な通知設計ができるようになりました
• 無駄な通知をふやさず、すでにある通知を更新しよう
• アプリ内通知で、システム通知画面を表示しよう

More Related Content

PPTX
スタートアップ勉強会
PDF
Xcode bot
PPTX
Apple ios
PDF
Universal Link
PDF
Swift3 typecasting nested_type
PDF
Study Swift
PDF
みんなで Swift 復習会での談笑用スライド – in 札幌 1st′ #minna_de_swift
PDF
コードを書きやすくしてくれる Xcode の基本機能 #NSStudy #devsap
スタートアップ勉強会
Xcode bot
Apple ios
Universal Link
Swift3 typecasting nested_type
Study Swift
みんなで Swift 復習会での談笑用スライド – in 札幌 1st′ #minna_de_swift
コードを書きやすくしてくれる Xcode の基本機能 #NSStudy #devsap

Viewers also liked (9)

PPTX
使った気になれるFirebase
PDF
AnyObject – 自分が見落としていた、基本の話
PDF
Swift 3 で新しくなったところ - 表面から見えにくいところを中心に紹介 #ISAOcorp
PDF
描画とビジネスをクリーンに分ける(公開用)
PPT
iOS 10 or Android Nougat? Who is leading the era
PDF
What's new Swift3
PDF
NS Prefix - そこから見渡す Swift 3 の景色 #startup_mobile
PDF
みんなで Swift 復習会での談笑用スライド – 6th #minna_de_swift
PDF
Swift イニシャライザー復習会 #love_swift #akibaswift #21cafe
使った気になれるFirebase
AnyObject – 自分が見落としていた、基本の話
Swift 3 で新しくなったところ - 表面から見えにくいところを中心に紹介 #ISAOcorp
描画とビジネスをクリーンに分ける(公開用)
iOS 10 or Android Nougat? Who is leading the era
What's new Swift3
NS Prefix - そこから見渡す Swift 3 の景色 #startup_mobile
みんなで Swift 復習会での談笑用スライド – 6th #minna_de_swift
Swift イニシャライザー復習会 #love_swift #akibaswift #21cafe
Ad

More from toyship (12)

PDF
Time for Xcode Behavior
PDF
Can we live in a pure Swift world?
PDF
Swift Protocol and Selector
PDF
Xcode7時代のアプリ配布
PDF
My first tvOS
PDF
3D touch for iOS
PDF
Contents blocker on iOS9
PDF
Embedded framework and so on
PDF
はじめてのWKInterfaceController
PDF
App extension for iOS
PDF
サーバーからiOSアプリを変更する
PDF
AVSpeechSynthesizerとロケール
Time for Xcode Behavior
Can we live in a pure Swift world?
Swift Protocol and Selector
Xcode7時代のアプリ配布
My first tvOS
3D touch for iOS
Contents blocker on iOS9
Embedded framework and so on
はじめてのWKInterfaceController
App extension for iOS
サーバーからiOSアプリを変更する
AVSpeechSynthesizerとロケール
Ad

Notifications in iOS10