简体   繁体   中英

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?

All you have to do is configure your App to respond to remote control events.

Remote Control events Remote control events are any event received for the purpose of controlling media. eg iTunes pause/play/next/previous buttons available from the control center, or remote-control events from play/pause buttons on headphones.

Here is a tutorial on the subject.

Then your watch glance will be able to control the Apps audio.

With the current API as of Watch OS2 and iOS9, rewriting an glance similar to the now playing glance is not possible.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM