16

Is there any way to launch the iOS App from Apple Watch?

Edit:- Tried using both api below but doesn't work:-

Apple Watch Code

Calling Inside interfaceController.m

+ (BOOL)openParentApplication:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo, NSError *error)) reply;    // launches containing iOS application on the phone. userInfo must be non-nil

iOS Code

Calling Inside Appdelegate.m

- (void) application:(UIApplication *) application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply
Luca Angeletti
  • 58,465
  • 13
  • 121
  • 148
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • You can pass the data between two application using `+ (BOOL)openParentApplication:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo, NSError *error)) reply; // launches containing iOS application on the phone. userInfo must be non-nil` but even i tried searching but could not find andy answers here – Aadil Keshwani Feb 27 '15 at 09:10
  • 1
    Yes, i am able to pass the data but i wanted to launch the iOS App using the above api from iwatch – Hussain Shabbir Feb 27 '15 at 09:11
  • I guess it is still in development we need to wait till they add methods for the same. Currently we have very limited methods available I am sure they will add it soon – Aadil Keshwani Feb 27 '15 at 09:15
  • Here is the link in which they mentioned the same using above api but does not work https://github.com/NilStack?tab=repositories – Hussain Shabbir Feb 27 '15 at 09:17
  • My guess is that you are using the Xcode 6.3 beta. You should be using 6.2 for Watch development. I am using those APIs and it is working for me with 6.2. – Stephen Johnson Feb 28 '15 at 00:08
  • Are you using Xcode 6.2 beta 2 version?? – Hussain Shabbir Feb 28 '15 at 00:38
  • possible duplicate of [How can I open the parent app on iPhone from my WatchKit app?](http://stackoverflow.com/questions/27884123/how-can-i-open-the-parent-app-on-iphone-from-my-watchkit-app) – stk Apr 05 '15 at 19:14

1 Answers1

22

The answer is actually pretty interesting. It is YES and NO.

You CAN open the app in the background through the openParentApplication:reply: method. That will launch the app in the background if it is terminated or backgrounded. It will just call the app if it is already in the foreground.

You CANNOT bring the iOS App to the foreground from the Watch Extension if it is not already foregrounded. That is against Apple's policies. While you can actually do it in the iOS Simulator, Apple has confirmed that you cannot do this on the device or submit the solution to the App Store. See this article on the dev forums for more information.

If you need to bring the iOS App to the foreground, the only way you can partially do this at the moment is to use the Handoff APIs. Here is another link to the Handoff Programming Guide. Once you read both of those documents carefully, you'll see exactly how the Handoff system works.

To implement, you'll need to add the WKInterfaceController updateUserActivity:userInfo:webpageURL: in the Watch Extension. Then you'll need to implement the UIApplicationDelegate application:continueUserActivity:restorationHandler: in your iOS app. Unfortunately, you will not be able to test this solution until you have an Apple Watch, but the docs clearly state this will be supported.

cnoon
  • 16,575
  • 7
  • 58
  • 66
  • 1
    Thanks for the answer, but how i can bring the iOS App to the foreground using Handoff APIs? Do you have any sample code which will do the same? – Hussain Shabbir Mar 03 '15 at 09:56
  • Hi @Hussain, I updated my answer accordingly to walk you through adding Handoff to your Watch Extension and iOS app. – cnoon Mar 03 '15 at 16:32
  • Thanks cnoon but in simulator, can i able to test?? – Hussain Shabbir Mar 03 '15 at 21:25
  • 1
    Unfortunately you cannot. You'll have to wait until you have an actual device to test like the rest of us. – cnoon Mar 04 '15 at 03:59
  • I think at this point you're overloading this question. I would suggest opening a new one that is more specific rather than asking revised questions within the same thread. – cnoon Mar 09 '15 at 19:13
  • @cnoon What happens in code when the host app is already in the foreground? Is there a way to detect this? – Van Du Tran May 04 '15 at 12:48
  • Your app will just receive the delegate call on the main thread since it is already opened. There is no easy way to tell if your app is in the foreground other than storing the state in an app group or asking the app directly in the `openParentApplication:reply:` method. – cnoon May 05 '15 at 00:47
  • Hi Cnoon, if i do not want to pass the webPageURL then how it works. Because i do not have any webPageUrl to pass just i need to launch the iOS app from watch? – Hussain Shabbir May 31 '15 at 01:57
  • 1
    @cnoon can i open watch app from iphone? – Tejas Ardeshna Oct 11 '17 at 13:30