简体   繁体   中英

How can I open the application on iPhone from my WatchKit app?

I am using watchkit in my application. I want to open application in iphone through watchkit.I have searched a lot but couldn't find anything. Any help would be appreceated.

i also tried below link How can I open the parent app on iPhone from my WatchKit app?

If you are work with Objective C then just put the following method in AppDelegate.m File.

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply {
    NSString * request = [userInfo objectForKey:@"requestString"];
    if ([request isEqualToString:@"executeMethodA"]) {
        // Do whatever you want to do when sent the message. For instance...
        //[self executeMethodABC];
    }
    reply(@{@"clicked from  watch":@(1)});
}

I hope this will help you.

Implementing the method

You should implement the receiving message method ( application:handleWatchKitExtensionRequest:reply ) in your AppDelegate file.

Swift: AppDelegate.swift

let message = userInfo.objectForKey("message") as! NSString
if message.isEqualToString("launchApp") {
    //Launch functions here
}

Objective-C: AppDelegate.m

NSString* message = [userInfo objectForKey:@"message"];
if ([message isEqualToString:@"launchApp"]) {
    // Launch functions here
}

Conclusion

1- You should implement the receiving message method in your App Delegate.

2- In Swift, the app delegate is AppDelegate.swift .

3- In Obj-C, the app delegate is AppDelegate.m .

4- The receiving message method is application:handleWatchKitExtensionRequest:reply .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM