3. Agenda
• About
• What is App Extension
• How to make App Extension
• How to share data Container and Extension
• App Group and Shared Container
• How to share codes between Container and Extension
• Information
11. How to make App Extension
• Extensionは、アプリのターゲットとして追加される
• ExtensionはContaining Appに含まれて単体でリリースす
ることはできない
12. How to make App Extension
• Extensionは、Contaning Appと同じipaに含まれてリ
リースされますが、Extensionは、Contaning Appアプリ
としては全く別の存在です。
• アプリから利用するサンドボックス、設定、メモリ
空間、のすべてで異なります。
• (ここのデータ共有する方法については後ほど説明し
ます)
13. How to make App Extension
• Containing App(本体アプリ)にターゲットを追加
• Extensionごとにターゲットのテンプレートがあるの
で、自分の作成したいExtensionを選択
14. How to make App Extension
• Extensionをターゲットとして追加すると、自動的に
ターゲットのinfo.plistと、Extensionの動作の中心となる
ViewControllerクラスのファイルが作成されます。
• 基本的な動作は、そのViewControllerクラスを拡張する
のみ
15. How to make App Extension
• Extensionは、Containing App(本体アプリ)とは別プロ
セスとなるため、独自のBundle Identifierを設定します。
• ただし、Containing AppとExtensionのBundle Identifier
は、同じPrefixを持つ必要があります。
• 例:Containing App: org.toyship.chat
• 例:Extension:org.toyship.chat.widget
16. How to make App Extension
• Extensionで使えないAPIがあります。
• NS_EXTENSION_UNAVAILABLE_IOS
+ (UIApplication *)sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based
solutions where appropriate instead.");
!
@property(nonatomic,assign) id<UIApplicationDelegate> delegate;
!
- (void)beginIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS("");
- (void)endIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS("");
- (BOOL)isIgnoringInteractionEvents;
!
@property(nonatomic,getter=isIdleTimerDisabled) BOOL idleTimerDisabled;
!
- (BOOL)openURL:(NSURL*)url NS_EXTENSION_UNAVAILABLE_IOS("");
- (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS(3_0);
17. How to make App Extension
• UIApplication.h
+ (UIApplication *)sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based
solutions where appropriate instead.");
!
@property(nonatomic,assign) id<UIApplicationDelegate> delegate;
!
- (void)beginIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS("");
- (void)endIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS("");
- (BOOL)isIgnoringInteractionEvents;
!
@property(nonatomic,getter=isIdleTimerDisabled) BOOL idleTimerDisabled;
!
- (BOOL)openURL:(NSURL*)url NS_EXTENSION_UNAVAILABLE_IOS("");
- (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS(3_0);
18. How to make App Extension
• UIApplication-sharedApplicationが使えない
• UIApplication-openURLも使えない
• UIViewControllerの新しいpropertyとして、
NSExtensionContextが追加されていて、Extensionではこ
のオブジェクトが取得できます。
• このクラスが、Hostアプリ-Extensionのデータのやり取
りやopenURLをサポートします。
19. How to make App Extension
• NSExtensionContext
@interface NSExtensionContext : NSObject
!
// HostアプリからExtensionに渡される入力データ
@property(readonly, copy, NS_NONATOMIC_IOSONLY) NSArray *inputItems;
!
// Hostアプリ側の処理が完了した時によばれる関数。終了時のBlockつき。これがよばれると、
UIViewControllerは終了する。
- (void)completeRequestReturningItems:(NSArray *)items completionHandler:(void(^)(BOOL
expired))completionHandler;
!
// Hostアプリが処理をキャンセルしたときによばれる
- (void)cancelRequestWithError:(NSError *)error;
!
// Asks the host to open an URL on the extension's behalf
- (void)openURL:(NSURL *)URL completionHandler:(void (^)(BOOL
success))completionHandler;
!
@end
20. How to make App Extension
NSExtensionContextで行われるデータの受け渡し
21. How to make App Extension
• Extension内でNSExtensionContext経由でopenURLを実
行
- (IBAction)openSomething:(id)sender {
[self.extensionContext
openURL:[NSURL URLWithString:@"http://www.apple.com/"]
completionHandler:nil];
!
}
22. How to make App Extension - Today
• 「Today Extension」ターゲッ
トを追加すると、
UIViewControllerが自動生成さ
れる。
• Storyboardの利用も可能
23. How to make App Extension - Today
• Today Extensionでは、表示領域が制限される
• Widgetの縦サイズを変更することは可能だが、デバイ
スの縦サイズが上限となっている
• UIScrollViewはおくべきでない
• Today Extensionではキーボード入力が不可となっている
ため、touch/gestureイベントのみで操作できるように実
装する
24. How to make App Extension - Share
• 「Share Extension」ター
ゲットを追加すると、
SLComposeServiceViewC
ontrollerが自動生成される
• Share用のDialogが用意さ
れているため、実装が容
易
25. How to make App Extension - Keyboard
• 「Custom Keyboard」ターゲッ
トを追加すると、
UIInputViewControllerが自動生成
される。
• 独自キーボード領域の描画・
処理を行うための
ViewController