11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Apple Watch アプリ開発 超初級チートシート

Last updated at Posted at 2015-06-12

この記事は watchOS 1.0.1 の時期に書かれています。その後のOSでは内容が正しくない可能性があります。

画面遷移

WKInterfaceController.h
- (void)pushControllerWithName:(NSString *)name context:(id)context;

[self pushControllerWithName:@"NextInterface" context:@{@"Text": @"Apple Watch"}];

name に Storyboard ID
context に 次の画面へ渡したい物

iPhone から データを取得する

Apple Watch 側

WKInterfaceController.h
+ (BOOL)openParentApplication:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo, NSError *error)) reply;

[WKInterfaceController openParentApplication:@{@“Action" : @“Type"}
                                       reply:^(NSDictionary *replyInfo, NSError *error) {
                                           NSLog(@"replyInfo: %@, error: %@", replyInfo, error.debugDescription);
                                       }];

iPhone 側

AppDelegate.h
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply;

NSString *actionType = userInfo[@"Action"];
if ( [actionType isEqualToString:@"Type"] ) {
    // do something
    reply(@{@“Reply : @“Value"});
}

Force Touch に対応する (メニューを表示する)

WKInterfaceController.h
- (void)addMenuItemWithImage:(UIImage *)image title:(NSString *)title action:(SEL)action;           // all parameters must be non-nil
- (void)addMenuItemWithImageNamed:(NSString *)imageName title:(NSString *)title action:(SEL)action;
- (void)addMenuItemWithItemIcon:(WKMenuItemIcon)itemIcon title:(NSString *)title action:(SEL)action;
- (void)clearAllMenuItems;

[self addMenuItemWithItemIcon:WKMenuItemIconAccept title:@"Accept" action:@selector(pushAcceptButton:)];

絵文字、サジェスト、音声入力に対応

WKInterfaceController.h
- (void)presentTextInputControllerWithSuggestions:(NSArray *)suggestions allowedInputMode:(WKTextInputMode)inputMode completion:(void(^)(NSArray *results))completion;

    [self presentTextInputControllerWithSuggestions:@[@"おはようございます", @"少々お待ちください", @"お疲れ様です"]
                                   allowedInputMode:WKTextInputModeAllowAnimatedEmoji
                                         completion:^(NSArray *results) {
                                         }
     ];

WKTextInputModePlain
サジェスト + 音声入力
WKTextInputModeAllowEmoji
絵文字 + サジェスト + 音声入力
WKTextInputModeAllowAnimatedEmoji
アニメーション絵文字 + 絵文字 + サジェスト + 音声入力

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?