アプリのバックグラウンド処理 | ios 7エンジニア勉強会
DESCRIPTION
TRANSCRIPT
2013.10.07
アプリのバックグラウンド処理iOS 7 エンジニア勉強会@ヤフー
平松 亮介 @himara2
自己紹介
・女子向けアプリ Petapic のiOS開発担当
・ヤフー株式会社CMOアプリ開発室
・アプリのバックグランド処理 について話します
フォトコミュニケーション部Kawaiiフォト加工チーム
バックグラウンド処理
・バックグラウンド状態でもアプリが活躍できる
・ex) 音楽を聞きながらFacebookアプリを使う
僕の来た道はバックグラウンドで位置を記録し続ける
マルチタスク関連のAPI
In iOS 6
task = [app beginBackgroundTaskWithExpirationHandler:^{ task = UIBackgroundTaskInvalid;};// ...[app endBackgroundTask:task];
• Used for■ Encoding video■ Uploads or downloads■ Completing database operations
Background Task Completion
Background Audio
Location Services
VoIP
Newsstand
In iOS 7
iPhone awake
Time
Background Fetch
Silent Push Notification
Background Transfer
NEW!!
便利な3つの新機能
BackgroundFetch
Silent PushNotification
BackgroundTransfer
概要Background Fetch
・アプリ使用の流れ(従来)
概要Background Fetch
・この遅延がユーザ体験を妨げている・起動したら即コンテンツ表示したい・アプリ使用の流れ(従来)
概要Background Fetch
・アプリ使用の流れ(with Background Fetch)
OSが適切なタイミングでコンテンツ更新を呼ぶ
In iOS 7
iPhone awake
Time
OSの学習Background Fetch
9:00
12:00
16:00
22:00
Day 1 Day 2 Day n Prediction
OSがユーザの行動パターンを解析
適切なタイミング
実装ポイントBackground Fetch
application:performFetchWithCompletionHandler:
AppDelegate
・Background Modes で “Background fetch” にチェック
・OSが適当なタイミングでアプリを起こし、処理を実行
・[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum];
・呼び出しの最短間隔を設定
Demo
Background Fetch
こんなアプリで使えるBackground Fetch
・日常的に, 頻繁に使われるアプリ
- アプリを起動したら最新情報が表示される!
便利な3つの新機能
BackgroundFetch
Silent PushNotification
BackgroundTransfer
概要Silent Push Notification
・Remote Push Notification の拡張版
Push通知(iOS 6) Silent Push Notification
APNs ①push
サーバー
⑤表示
③起動
④コンテンツ更新
②通知表示
apns {alert : { ... }
}
Push通知(iOS 7) Silent Push Notification
APNs ①push
サーバー
⑤アプリ表示
②バックグラウンド
でコンテンツ更新
で起動
③バックグラウンド
④通知表示
apns {content-available:1, alert : { ... }
}
Silent Push Notification実装ポイント
application:didReceiveRemoteNotification:fetchCompletionHandler
AppDelegate
・Background Modes で “Remote notifications” にチェック
・silent pushを受け取ったタイミングで処理を実行
Silent Push Notification
Demo
こんなアプリで使えるSilent Push Notification
・不定期にコンテンツを受け取るサービス- メッセージングサービスやメールなど
- Pushが届いて開くと最新のメッセージが表示されている!
便利な3つの新機能
BackgroundFetch
Silent PushNotification
BackgroundTransfer
概要Background Transfer
・バックグラウンドで大容量ファイルのDL/ULが可能に
- Task Completionのような時間制限はない
・プロセスはOSが管理してくれる
Background Transfer
Demo
こんなアプリで使えるBackground Transfer
・容量の大きなファイルを扱うアプリ
注意Background Transfer
・バックグラウンドでのDL/ULはWi-Fi下でのみ発動
・Background Fetch, Silent Pushと組み合わせると強力
コンテンツに変更があった→ Silent Pushで端末を起こす→大容量のファイルをBackground Transferで同期→完了したらLocal Notificationで通知
その他
ユーザ設定
・設定からBackground実行を制限できる- Location Services- Background Fetch- Silent Push Notification- Background Transfer
設定 > 一般 > Appのバックグラウンド更新
・設定状態を取得するAPIが Coming soon.
App Switcher
・「UIが良いとユーザは復帰する」
ホームボタンを2回クリック
・App Switcherで消すと, アプリはバックグラウンド動作☓
End
What’s New With Multitasking
Ryosuke Hiramatsu
iOS 7 study