Saurabh Patel
Saurabh Patel

Reputation: 21

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?

Upvotes: 2

Views: 130

Answers (2)

Jagat Dave
Jagat Dave

Reputation: 1645

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.

Upvotes: 4

Seyed Parsa Neshaei
Seyed Parsa Neshaei

Reputation: 3520

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.

Upvotes: 0

Related Questions