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
630
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
2
1.6k
AWSに止められる覚悟してますか?
morizo_1984
2
530
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
290
R8 の設定見直しでアプリサイズ削減
andpad
0
220
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
160
ActionController meets Protocol Buffers
sorah
0
520
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
Jetpack Compose Mechanisms
skydoves
3
820
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
New Earth Scene 8
popppiees
4
2.7k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
570
Exploring anti-patterns in Rails
aemeredith
4
540
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
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(ʹݶΒͣ) ΤϯδχΞืूதʂ