iosobjective-ciphonewatchos-2

How to wake iphone on applewatch programmatically


My scenario is control iphone music player on applewatch. Just like what the applewatch music glance would do. The project is gonna be iphone app, watch app, and watch extension. however, I want it to be able to work even thou my iphone app is not active. I know when iphone app is active, I could use wcsession and sendMessage to control the music on iphone. However, when the iphone app is not active. I don't know what I should do to get the work done.

One more thing, I don't understand how iphone app works when it is not active. Does it need to be active first do those job, or it is never really inactive so it could still do work?


Solution

  • Use this to wake up your iPhone App from your watch kit App in the background:

    from https://developer.apple.com/library/prerelease/watchos/documentation/General/Conceptual/AppleWatch2TransitionGuide/UpdatetheAppCode.html

    Interactive messaging mode

    sendMessage:replyHandler:errorHandler:

    sendMessageData:replyHandler:errorHandler:

    Use this mode to send data immediately to a counterpart app. If you do not want a response, you may specify nil for the replyHandler parameter. The counterpart app must be reachable before calling this method. The iOS app is always considered reachable, and calling this method from your Watch app wakes up the iOS app in the background as needed. The Watch app is considered reachable only while it is installed and running. Data is transmitted immediately and messages are queued and delivered in the order in which they were sent.