Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ios_push_local_notification
Search
WorldDownTown
February 23, 2014
Programming
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ios_push_local_notification
iOS, Objective-C, Push Notification, Local Notification
WorldDownTown
February 23, 2014
More Decks by WorldDownTown
See All by WorldDownTown
WWDC動画鑑賞会📹🍱を支える技術 / WWDC Video Lunch
worlddowntown
0
340
Live Renderingとの上手い付き合い方
worlddowntown
1
610
In-App Purchase / Subscription with StoreKit
worlddowntown
3
3.1k
20150225_iqon.pdf
worlddowntown
0
110
iqon_ios_growth_hack
worlddowntown
3
4.4k
Other Decks in Programming
See All in Programming
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
1
690
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
1k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
FreeBSDでZabbixを動かす
kenkino
0
340
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
110
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.2k
setup-vp GitLab対応の裏側
naokihaba
0
140
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
280
Security issues being discussed on Web Platforms
petamoriken
0
1.4k
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
19
19k
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
600
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1k
Featured
See All Featured
How GitHub (no longer) Works
holman
316
150k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
440
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
690
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
440
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
How to Ace a Technical Interview
jacobian
280
24k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Unsuck your backbone
ammeep
672
58k
Site-Speed That Sticks
csswizardry
13
1.5k
Being A Developer After 40
akosma
91
590k
Building an army of robots
kneath
307
47k
How to Think Like a Performance Engineer
csswizardry
28
2.8k
Transcript
1VTI-PDBM /PUJpDBUJPO ͱͦͷपล 2014/2/23 ঙ࢘ ܒี
ࣗݾհ • ঙ࢘ ܒี • twitter/github: WorldDownTown • iOSྺ1 iQONͷiOSΤϯδχΞ
J20/
J20/ ϑΝογϣϯࡶࢽΛݟΔΑ͏ʹτϨϯυ͕Θ͔ͬͯɺ ݟ͍ͯΔͷ͕௨ൢͰ͖ΔແྉͷϑΝογϣϯ ίʔσΟωʔτΞϓϦ AppStoreͷ2012ϕετΞϓϦʹબग़ʂ
࣍ • Push / Local Notification ͱʁ • Push Notification
• Local Notification • Push / Local Notificationൺֱ • iOS7ͷػೳ • ·ͱΊ
Push / Local Notification ͬͯ·͔͢ʁ
Push / Local Notification ͱʁ
Push / Local Notification ͱʁ ϩʔΧϧ௨͓Αͼϓογϡ௨͕ղܾ͢Δ ϑΥΞάϥϯυͰɺʹͭͷΞϓϦέʔγϣϯ͔͠ΞΫςΟϒʹͳΕ·ͤΜɻ ଟ͘ͷΞϓϦέʔγϣϯɺ࣌ؒϕʔε·ͨ૬ޓଓ͞ΕͨڥͰಈ࡞͍ͯ͠Δͨ ΊɺΞϓϦέʔγϣϯ͕ϑΥΞάϥϯυʹͳ͍ͱ͖ʹɺϢʔβ͕ؔ৺Λ͍࣋ͬͯΔ Πϕϯτ͕ൃੜ͢ΔՄೳੑ͕͋Γ·͢ɻ
ϩʔΧϧ௨͓Αͼϓογϡ௨ʹΑΓɺΞϓϦέʔγϣϯɺ͜ΕΒͷΠϕϯτ͕ ൃੜͨ͜͠ͱΛϢʔβʹ௨Ͱ͖ΔΑ͏ʹͳΓ·͢ɻ ʰ-PDBM͓Αͼ1VTI/PUJpDBUJPOϓϩάϥϛϯάΨΠυʱ
Push / Local Notification ͱʁ ϩʔΧϧ௨͓Αͼϓογϡ௨͕ղܾ͢Δ ϑΥΞάϥϯυͰɺʹͭͷΞϓϦέʔγϣϯ͔͠ΞΫςΟϒʹͳΕ·ͤΜɻ ଟ͘ͷΞϓϦέʔγϣϯɺ࣌ؒϕʔε·ͨ૬ޓଓ͞ΕͨڥͰಈ࡞͍ͯ͠Δͨ ΊɺΞϓϦέʔγϣϯ͕ϑΥΞάϥϯυʹͳ͍ͱ͖ʹɺϢʔβ͕ؔ৺Λ͍࣋ͬͯΔ Πϕϯτ͕ൃੜ͢ΔՄೳੑ͕͋Γ·͢ɻ
ϩʔΧϧ௨͓Αͼϓογϡ௨ʹΑΓɺΞϓϦέʔγϣϯɺ͜ΕΒͷΠϕϯτ͕ ൃੜͨ͜͠ͱΛϢʔβʹ௨Ͱ͖ΔΑ͏ʹͳΓ·͢ɻ ʰ-PDBM͓Αͼ1VTI/PUJpDBUJPOϓϩάϥϛϯάΨΠυʱ ར༻্ʹͭͳ͕Δ
Push / Local Notification ͱʁ • ܯࠂόφʔ͕දࣔ͞ΕΔ • ΞϓϦέʔγϣϯΞΠίϯʹόοδ͕ͭ͘ •
αϯυ͕໐Δ Ϣʔβʔʹͱͬͯ Push NotificationLocal Notification ಉ͡ʹݟ͑Δ
Push / Local Notification ͱʁ • ࣮ํ๏ͷҧ͍ • ϝϦοτ/σϝϦοτͷҧ͍ ΞϓϦέʔγϣϯʹͱͬͯ
Push NotificationͱLocal Notification ҧ͏ʹݟ͑Δ
࣍ • Push / Local Notification ͱʁ • Push Notification
• Local Notification • Push / Local Notificationൺֱ • iOS7ͷػೳ • ·ͱΊ
1VTI/PUJpDBUJPO
1VTI/PUJpDBUJPO • iPhone OS 3.0ʙ • αʔό͔ΒiOS௨ΛૹΔ • αʔό͔Βҙͷϝοηʔδ/λΠϛϯά Ͱૹ৴Մೳ
1VTI/PUJpDBUJPOͷΈ 1. Apple Push Notification Service (APNs) ͱ͍͏ήʔτΣΠʹσόΠε Λొ
2. σόΠε͕APNs͔ΒdeviceTokenΛड͚औΔ 3. ΞϓϦ͕σόΠε͔ΒdeviceTokenΛड͚औΔ 4. deviceTokenΛϓϩόΠμ(ΞϓϦ ӡӦऀͷαʔό)ʹొ͢Δ
1VTI/PUJpDBUJPOͷΈ 1. ϓϩόΠμdeviceTokenͱpayloadΛؚΉ௨ύοέʔδΛ࡞ ϦϞʔτ௨ͷσʔλҰํʹྲྀΕΔ 2. ϓϩόΠμͦͷ௨ΛAPNsʹૹ৴ 3. APNs͕ͦͷ௨ΛσόΠεʹ৴ʢϓογϡʣ
1VTI/PUJpDBUJPOΛૹΔ ४උ • ϓϩόΠμͷڥߏங • σόΠετʔΫϯઃఆॲཧ࣮
ϓϩόΠμͷڥߏங লུ
ϓϩόΠμͷڥߏங ໘ͳڥઃఆΛ͠ͳ͍͍ͯ͘Α͏ʹͳ͖ͬͯ·ͨ͠
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // APNsにデバイス登録 UIRemoteNotificationType notificationType
= UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationType]; ! return YES; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *deviceTokenString = deviceToken.description; NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"<>"]; deviceTokenString = [deviceTokenString stringByTrimmingCharactersInSet:characterSet]; deviceTokenString = [deviceTokenString stringByReplacingOccurrencesOfString:@" " withString:@""]; ! // deviceTokenStringをサーバに送信 } σόΠετʔΫϯ ઃఆॲཧ࣮ UIApplicationDelegateͷԼهͷϝιουΛ࣮
͜ΕͰ४උྃ ϓϩόΠμ͔Β 1VTIૹ৴Մೳ
Ԡ༻ • payloadͷΧελϜϓϩύςΟ • σόΠετʔΫϯઃఆλΠϛϯά
QBZMPBEͷΧελϚΠζ { "aps":{ "alert":"hello", "badge":1, "sound":"default" } } γϯϓϧͳQBZMPBE
QBZMPBEͷΧελϚΠζ { "aps":{ "alert":{ "body":"hello", "action-loc-key":"ゲームを再開", "launch-image":"push.png" }, "badge":1, "sound":"default"
} } BMFSUͷࢠϓϩύςΟͰΧελϚΠζͰ͖Δ
QBZMPBEͷΧελϚΠζ BMFSUͷࢠϓϩύςΟ Ωʔ ͷܕ આ໌ CPEZ จࣈྻ 1VTI௨࣌ͷϝοηʔδ BDUJPOMPDLFZ จࣈྻ
1VTIىಈϘλϯͷϝοηʔδ MPDLFZ จࣈྻ 1VTI௨࣌ͷϩʔΧϥΠζϝοηʔδ -PDBMJ[BCMFTUSJOHTϑΝΠϧͷΩʔΛ༩͑Δ MPDBSHT จࣈྻͷྻ MPDLFZͷॻࣜࢦఆࢠͷΘΓʹ දࣔ͢Δมจࣈྻ MBVODIJNBHF จࣈྻ 1VTI͔Βͷىಈ࣌ʹදࣔ͞ΕΔը૾ͷϑΝΠϧ໊ ࢦఆ͠ͳ͚Ε%FGBVMUQOH
QBZMPBEͷΧελϚΠζ BDUJPOMPDLFZ
QBZMPBEͷΧελϚΠζ { "aps":{ "alert":"hello", "badge":1, "sound":"default" }, "key":"value" } ΞϓϦέʔγϣϯʹLFZWBMVFΛ͢͜ͱ͕Ͱ͖Δ
Push௨ىಈͷϩάΛམͱͨ͠Γ! ىಈ࣌ͷViewControllerΛࢦఆͨ͠ΓͰ͖Δ
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSMutableDictionary *payload = [launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]
mutableCopy]; payload[@"type"] = @"not_running"; if (payload) { // アプリの未起動時にプッシュ通知を受け取り、ユーザーがアクションボタンをタップしたとき // payload[@"key"] -> value [self startWithPayload:payload]; } return YES; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { NSMutableDictionary *payload = userInfo.mutableCopy; if (application.applicationState == UIApplicationStateActive) { // フォアグラウンドでプッシュ通知を受け取ったとき payload[@"type"] = @"active"; } else { // アプリがサスペンド中にプッシュ通知を受け取り、ユーザーがアクションボタンをタップしたとき payload[@"type"] = @"background"; } // payload[@"key"] -> value [self startWithPayload:payload]; } UIApplicationDelegateͷԼهͷϝιουΛ࣮ QBZMPBEͷΧελϚΠζ
σόΠετʔΫϯઃఆͷ λΠϛϯά - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // APNsにデバイス登録
UIRemoteNotificationType notificationType = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationType]; ! return YES; } Α͘ݟΔαϯϓϧ
σόΠετʔΫϯઃఆͷ λΠϛϯά ·ͩͲΜͳΞϓϦ͔Α͘Θ͔Βͳ͍ͷʹɺ! ॳճىಈͷλΠϛϯάͰϓογϡͷڐՄ! Λฉ͍ͯ͠·͏ͱڐՄͯ͠Β͑ͳ͍…
σόΠετʔΫϯઃఆͷ λΠϛϯά νϡʔτϦΞϧʹ͋ΔΑ͏ʹ! application:didFinishLaunchingWithOptions: Ͱ! registerForRemoteNotificationTypesΛίʔϧͤͣɺ! ϓογϡ௨Λड͚औΔϝϦοτड़ͨ͏͑Ͱ! ॳΊͯregisterForRemoteNotificationTypes:Λίʔϧ͢Δ iQONͰPUSHઃఆ্͕!
࣍ • Push / Local Notification ͱʁ • Push Notification
• Local Notification • Push / Local Notificationൺֱ • iOS7ͷػೳ • ·ͱΊ
-PDBM/PUJpDBUJPO • iOS 4.0ʙ • ໘ͳϓϩόΠμઃఆ͕ෆཁ • λΠϚʔ܁Γฦ͠Ͱ௨ΛදࣔͰ͖Δ • ΞϓϦ͕OSʹରͯ͠௨ͷεέδϡʔϧ
ςΩετΛઃఆ͢Δ
௨ઃఆ UILocalNotification *notification = [UILocalNotification new]; notification.alertBody = @"UILocalNotificationのテスト"; //
アラートメッセージ notification.fireDate = [[NSDate date] dateByAddingTimeInterval:(60 * 3)]; // 3分後に通知 notification.applicationIconBadgeNumber = 1; // アプリアイコンのバッジ数 notification.timeZone = [NSTimeZone localTimeZone]; // タイムゾーン notification.alertAction = @"起動して!"; // 起動ボタンのテキスト notification.hasAction = NO; // YESならアラートからアプリを起動しない notification.soundName = UILocalNotificationDefaultSoundName; // 通知音 notification.alertLaunchImage = @"push.png"; // 起動時の画像指定しなければDefault.png notification.userInfo = @{@"id":@1234}; // カスタムプロパティ [[UIApplication sharedApplication] scheduleLocalNotification:notification]; // 通知の予約 Push NotificationʹൺͨΒྦ͕ग़Δ΄Ͳ؆୯! Push Notificationͱಉ͡Α͏ͳࡉ͔͍Φϓγϣϯ͋Δ
௨Ωϟϯηϧ NSArray *notifications = [UIApplication sharedApplication].scheduledLocalNotifications; for (UILocalNotification *notification in
notifications) { if ([notification.userInfo[@"id"] integerValue] == 1234) { [[UIApplication sharedApplication] cancelLocalNotification:notification]; } } ΧϨϯμʔΞϓϦͰεέδϡʔϧΛআ࣌͠ͳͲɺ! ௨ΛΩϟϯηϧ͢Δ͜ͱ͕Ͱ͖Δ [[UIApplication sharedApplication] cancelAllLocalNotifications]; શͯͷ௨ΛΩϟϯηϧ ಛఆͷ௨ΛΩϟϯηϧ͢ΔʹuserInfoͷใ͔ΒΩϟϯηϧ͢Δ௨Λಛఆ͢Δ
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UILocalNotification *notification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) { // アプリの未起動時に通知を受け取り、ユーザーがアクションボタンをタップしたとき // notification.userInfo[@"key"] -> value [self startWithNotification:notification]; } return YES; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { if (application.applicationState == UIApplicationStateActive) { // フォアグラウンドで通知を受け取ったとき } else { // アプリがサスペンド中に通知を受け取り、ユーザーがアクションボタンをタップしたとき } // notification.userInfo[@"key"] -> value [self startWithNotification:notification]; } UIApplicationDelegateͷԼهͷϝιουΛ࣮ (Push Notificationͱ΄΅ಉ͡) ىಈ࣌ͷ੍ޚ
-PDBM/PUJpDBUJPOԠ༻ྫ Sleipnir͕νϡʔτϦΞϧͱͯ͠Local Notification! Λར༻͍ͯ͠Δ
-PDBM/PUJpDBUJPOԠ༻ྫ ࣮Λ૾ͯ͠Έͨ • AppDelegateͷapplicationWillResignActive:Ͱ௨ͷઃఆ • notification.soundName = nil; • νϡʔτϦΞϧͱ͍ͯ͑ͨ͠ػೳΛطʹͬͨ͜ͱ͕
͋Δ߹ɺ௨ΛΩϟϯηϧ
࣍ • Push / Local Notification ͱʁ • Push Notification
• Local Notification • Push / Local Notificationൺֱ • iOS7ͷػೳ • ·ͱΊ
1VTI-PDBM/PUJpDBUJPOൺ ֱ 1VTI/PUJpDBUJPO -PDBM/PUJpDBUJPO ઃఆڥߏங ϓϩόΠμڥ 1SPWJTJPOJOHͷઃఆ͕ ඞཁ ωΠςΟϒͷίʔυ ͷΈ
௨λΠϛϯά ϓϩόΠμଆ͔Β ҙʹมߋՄೳ εέδϡʔϦϯά͕Մೳͩ ͕ɺ ௨Λઃఆ͢ΔͷΞϓϦى ಈத ௨ςΩετ ϓϩόΠμଆ͔Β ҙʹมߋՄೳ ΞϓϦ෦Ͱઃఆ มߋ͢ΔʹΞϓϦͷόʔδ ϣϯΞοϓ͕ඞཁ
࣍ • Push / Local Notification ͱʁ • Push Notification
• Local Notification • Push / Local Notificationൺֱ • iOS7ͷػೳ • ·ͱΊ
#BDLHSPVOE'FUDI
J04·Ͱͷ͓͞Β͍ • ΞϓϦ͕όοΫάϥϯυʹͳͬͨࡍͷॲཧ Իָ࠶ੜɺҐஔใऔಘɺVoIPͷΈՄೳ • ͦΕҎ֎UIApplicationͷ beginBackgroundTaskWithExpirationHandler: Ͱ όοΫάϥϯυʹߦ͔ͬͯΒ10͚ؒͩॲཧ ͕Մೳͩͬͨɻ10ޙʹαεϖϯυ͢Δ
#BDLHSPVOE'FUDI • iOS7ͰBackground ModeʹՃ͞Εͨ • 10ͷ੍ݶͳ͘ͳͬͨ • OS͕࠷దͱஅͨ͠λΠϛϯάͰόοΫάϥ ϯυॲཧΛߦ͏ •
ݺͼग़͠λΠϛϯάϢʔβʔͷΞϓϦͷར༻ ঢ়گΛΈֶͯश͢Δ
3FNPUF/PUJpDBUJPOT • iOS7ͰBackground ModeʹՃ͞Εͨ • Push NotificationΛΩʔʹόοΫάϥϯυͰॲ ཧΛ࣮ߦ͢Δ͜ͱ͕Ͱ͖Δ
3FNPUFOPUJpDBUJPOT ઃఆํ๏ XcodeͷCapabilitiesઃఆͰBackgroundMode > Remote notificationsʹνΣοΫ
UIApplicationDelegateͷԼهͷϝιουΛ࣮ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { //
コンテンツのダウンロード処理など ! if (success) { if (hasData) { // データ取得成功 completionHandler(UIBackgroundFetchResultNewData); } else { // データなし completionHandler(UIBackgroundFetchResultNoData); } } else { // データ取得失敗 completionHandler(UIBackgroundFetchResultFailed); } } 3FNPUFOPUJpDBUJPOT ઃఆํ๏
{ "aps":{ "alert":"hello", "badge":1, "sound":"default", "content-available":1 } } ϓϩόΠμ͕ૹ৴͢ΔQBZMPBEʹzDPOUFOUBWBJMBCMFzΛՃ͢Δͱ 3FNPUFOPUJpDBUJPOT
QBZMPBE - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler ͕࣮ߦ͞ΕΔ
{ "aps":{ "content-available":1 } } 4JMFOU1VTI QBZMPBEͷϝοηʔδΛࢦఆͤͣʹzDPOUFOUBWBJMBCMFz͚ͩࢦఆ͢Δͱɺ ௨͕දࣔ͞Εͣʹɺॲཧ͚࣮ͩߦ͞ΕΔ 4JMFOU1VTI
ҙ • όοΫάϯυͰΞϓϦ͕ىಈͯ͠ ͍ͳ͍ͱॲཧݺͼग़͞Εͳ͍ • iOSͷઃఆͰΞϓϦ͝ͱʹόοΫάϥ ϯυॲཧͷڐՄΛऔΓফ͢͜ͱ͕ Ͱ͖Δ ඞਢػೳͱͯ͠ఏڙ͢Δͷةݥ
࣍ • Push / Local Notification ͱʁ • Push Notification
• Local Notification • Push / Local Notificationൺֱ • iOS7ͷػೳ • ·ͱΊ
·ͱΊ 1VTI/PUJpDBUJPO • ॳճͷઃఆڥߏங͕໘ • ͦΕͰϢʔβʔ࠶ར༻ΛߴΊΔʹ ඞਢػೳ
·ͱΊ -PDBM/PUJpDBUJPO • ઃఆ͕؆୯ • ΧϨϯμʔToDoΞϓϦͳͲϢʔβʔͱ ͷίϛϡχέʔγϣϯ͕ແ͍ΞϓϦʹ ͍ͯΔ
·ͱΊ #BDLHSPVOE'FUDI • େ͖ͳσʔλΛಡΈࠐΉΑ͏ͳΞϓϦ PushͱΈ߹ΘͤΔͱ͍͍͔ • όοΫάϥϯυͰ͔͠ಈ͔ͳ͍ͷͰɺ ඞਢػೳͱ࣮ͯ͢͠Δͷةݥ
8"/5&% https://www.wantedly.com/projects/5530 iOS(ʹݶΒͣ) ΤϯδχΞืूதʂ