Chat with Watch to kill an iOS app using WatchConnectivity

Using WatchOS2 and WatchConnectivity , is it possible to “wake up” an iOS copy to send a message using “interactive messaging”?

The reason I'm asking is because I have a WatchOS1 application that uses openParentApplication to send / receive messages that really wake the iOS application if it doesn’t work, forces it to receive my message and allows it to send a response. After of this, he again closes the iOS application.

I'm a little confused how to do the same in WatchOS2. Because when I use "interactive messaging" using WCSession , the sent message is not delivered when I kill the iOS application.

I also noticed that WatchOS2 now contains all kinds of frameworks that you can use, such as NSURLSession and EventKit , which delegates all calls to the iPhone. So maybe this is the recommended way? For my watch app, coincidentally, only events from EventKit . So I could rewrite the WatchConnectivity part of my application to use EventKit . And if my application has to use HTTP, I could use NSURLSession directly.

Can anyone confirm that the alleged way to communicate with the iPhone now in WatchOS2 is to use such as CoreData / EventKit / etc? It makes sense if it is, but I really want someone to confirm this.

Thanks in advance.

+5
source share
2 answers

You must install WCSession in the part of your iOS application that starts when the iOS application is running in the background ( UIApplicationDelegate application:didFinishLaunchingWithOptions: will be one of these places, and any UIViewController viewDidLoad will not be one of them)

+3
source

WCSession is the recommended method of communication between a watch device and iOS.

For immediate use, use the sendMessage:replyHandler:errorHandler: method of the sendMessage:replyHandler:errorHandler: instance. According to the documentation :

Calling this method from your WatchKit extension while it is active and starting wakes up the corresponding iOS application in the background and makes it available.

In cases where another device cannot be reached, for example, because it is out of range, you can use the updateApplicationContext:error: method. It will queue the data and deliver it later to another device.

+4
source

Source: https://habr.com/ru/post/1231971/


All Articles