2

I just get started with WatchKit and I'm trying to do this (if I'm not wrong, it is possible to do): I'd like the WatchKit Extension to ask the containing app for requesting some data to a web service, and then return the service response to the Extension to update the WatchKit App interface accordingly.

As I read in Apple Watch Programming Guide, yo can call the openParentApplication:reply: method in the WatchKit Extension to request something to its containing app, and then the application:handleWatchKitExtensionRequest:reply: method in the AppDelegate of the containing app should be called. Once this method called, I need to perform the service request, wait for its response, and then send it back to the Extension.

However, when I run the WatchKit App scheme in the simulator, the openParentApplication:reply: method is called, but a breakpoint within the application:handleWatchKitExtensionRequest:reply: is not reached. So I'm not even able to test if I can correctly perform the web service request and get its response back.

What could I be missing? Should I configure somehow the schema to reach breakpoints in the containing app as well? Is it needed to declare some kind of background feature for this?

Thanks in advance

AppsDev
  • 12,319
  • 23
  • 93
  • 186

1 Answers1

3

I just answered a very similar question here which will allow you to open the iOS app from the Watch Extension and getting a reply back.

In order to debug the iOS app while running the Watch Extension, you should follow the steps explained here.

Community
  • 1
  • 1
cnoon
  • 16,575
  • 7
  • 58
  • 66
  • Thanks! One more question: since getting the response from the service is an asynchronous task... what should be the correct way to wait for the response, and then return it to the WatchKit Extension? – AppsDev Mar 14 '15 at 21:46
  • Simple...call the `reply` closure once the asynchronous task is complete. This will most likely be in the completion handler closure of the asynchronous task. – cnoon Mar 14 '15 at 23:38
  • Understood, thanks! I'm also calling `beginBackgroundTaskWithExpirationHandler:` just in case the asynchronous request takes too long... I think this is the correct way. – AppsDev Mar 15 '15 at 14:53