Search code examples
iosiphonewatchkitapple-watchwatchconnectivity

Implement WatchApp for already existing iPhone app and want api calls to happen on iPhone app in background mode


I am implementing WatchApp for already existing iPhone app and want api calls to happen on iPhone app in background mode. Please suggest how to do it. My iPhone code is in Obj-C and want Watch code to be in Swift. For the network queries from Watch should be handled on iPhone in background. Is it possible and how?


Solution

  • You can call WCSession.sendMessage in your watch app.

    When your iOS app is reachable, the corresponding WCSessionDelegate callback method is called even when your app is in background. (works fine in my App).

    When your watch app is not reachable, sendMessage is thrown away. When the your iOS app answers and it is not possible to transfer the answer to the watch, the answer is thrown away.

    P.S. As Apple suggests, do the iOS implementation in your AppDelegate. If you do it that way, your app can answer in background when no UIViewController instance exists.