Launch watch kit app from within another watch kit

2019-05-26 07:02发布

问题:

I know on the phone it is possible to launch an application from within another using something along the lines of...

-(IBAction) openYoutube:(id)sender {
      UIApplication *ourApplication = [UIApplication sharedApplication];
      NSString *ourPath = @"http://www.youtube.com/watch?v=TFFkK2SmPg4";
      NSURL *ourURL = [NSURL URLWithString:ourPath];
      [ourApplication openURL:ourURL];
}

This will launch the youtube app

My research hasn't led to anything useful and I doubt there is something out there, but what's the harm in asking to be sure. Is there anyway to accomplish this sort of functionality from the apple watch? Like if the user hits a button, I want my watch kit app to launch the instagram or twitter watch kit app

回答1:

Fortunately, you can. You can ask the iOS app to do this. Use this method

[WKInterfaceController openParentApplication:@{[results firstObject]:[results firstObject]} reply:^(NSDictionary *replyInfo, NSError *error) {
    }];

To call your parent iOS app. Within the iOS app, implement this delegate method to achieve what you want (in your AppDelegate).

(void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply{}


标签: watchkit