アプリのバックグラウンド処理 | ios 7エンジニア勉強会

28
2013.10.07 アプリのバックグラウンド処理 iOS 7 エンジニア勉強会@ヤフー 平松 亮介 @himara2

Upload: yahoo

Post on 15-Jan-2015

39.263 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

2013.10.07

アプリのバックグラウンド処理iOS 7 エンジニア勉強会@ヤフー

平松 亮介 @himara2

Page 2: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

自己紹介

・女子向けアプリ Petapic のiOS開発担当

・ヤフー株式会社CMOアプリ開発室

・アプリのバックグランド処理 について話します

フォトコミュニケーション部Kawaiiフォト加工チーム

Page 3: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

バックグラウンド処理

・バックグラウンド状態でもアプリが活躍できる

・ex) 音楽を聞きながらFacebookアプリを使う

僕の来た道はバックグラウンドで位置を記録し続ける

Page 4: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

マルチタスク関連の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!!

Page 5: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

便利な3つの新機能

BackgroundFetch

Silent PushNotification

BackgroundTransfer

Page 6: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

概要Background Fetch

・アプリ使用の流れ(従来)

Page 7: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

概要Background Fetch

・この遅延がユーザ体験を妨げている・起動したら即コンテンツ表示したい・アプリ使用の流れ(従来)

Page 8: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

概要Background Fetch

・アプリ使用の流れ(with Background Fetch)

OSが適切なタイミングでコンテンツ更新を呼ぶ

In iOS 7

iPhone awake

Time

Page 9: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

OSの学習Background Fetch

9:00

12:00

16:00

22:00

Day 1 Day 2 Day n Prediction

OSがユーザの行動パターンを解析

適切なタイミング

Page 10: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

実装ポイントBackground Fetch

application:performFetchWithCompletionHandler:

AppDelegate

・Background Modes で “Background fetch” にチェック

・OSが適当なタイミングでアプリを起こし、処理を実行

・[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum];

・呼び出しの最短間隔を設定

Page 11: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

Demo

Background Fetch

Page 12: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

こんなアプリで使えるBackground Fetch

・日常的に, 頻繁に使われるアプリ

- アプリを起動したら最新情報が表示される!

Page 13: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

便利な3つの新機能

BackgroundFetch

Silent PushNotification

BackgroundTransfer

Page 14: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

概要Silent Push Notification

・Remote Push Notification の拡張版

Page 15: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

Push通知(iOS 6) Silent Push Notification

APNs ①push

サーバー

⑤表示

③起動

④コンテンツ更新

②通知表示

apns {alert : { ... }

}

Page 16: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

Push通知(iOS 7) Silent Push Notification

APNs ①push

サーバー

⑤アプリ表示

②バックグラウンド

でコンテンツ更新

で起動

③バックグラウンド

④通知表示

apns {content-available:1, alert : { ... }

}

Page 17: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

Silent Push Notification実装ポイント

application:didReceiveRemoteNotification:fetchCompletionHandler

AppDelegate

・Background Modes で “Remote notifications” にチェック

・silent pushを受け取ったタイミングで処理を実行

Page 18: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

Silent Push Notification

Demo

Page 19: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

こんなアプリで使えるSilent Push Notification

・不定期にコンテンツを受け取るサービス- メッセージングサービスやメールなど

- Pushが届いて開くと最新のメッセージが表示されている!

Page 20: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

便利な3つの新機能

BackgroundFetch

Silent PushNotification

BackgroundTransfer

Page 21: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

概要Background Transfer

・バックグラウンドで大容量ファイルのDL/ULが可能に

- Task Completionのような時間制限はない

・プロセスはOSが管理してくれる

Page 22: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

Background Transfer

Demo

Page 23: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

こんなアプリで使えるBackground Transfer

・容量の大きなファイルを扱うアプリ

Page 24: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

注意Background Transfer

・バックグラウンドでのDL/ULはWi-Fi下でのみ発動

・Background Fetch, Silent Pushと組み合わせると強力

コンテンツに変更があった→ Silent Pushで端末を起こす→大容量のファイルをBackground Transferで同期→完了したらLocal Notificationで通知

Page 25: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

その他

Page 26: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

ユーザ設定

・設定からBackground実行を制限できる- Location Services- Background Fetch- Silent Push Notification- Background Transfer

設定 > 一般 > Appのバックグラウンド更新

・設定状態を取得するAPIが Coming soon.

Page 27: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

App Switcher

・「UIが良いとユーザは復帰する」

ホームボタンを2回クリック

・App Switcherで消すと,  アプリはバックグラウンド動作☓

Page 28: アプリのバックグラウンド処理 | iOS 7エンジニア勉強会

End

What’s New With Multitasking

Ryosuke Hiramatsu

iOS 7 study