WatchOS 2 Complication Update From iPhone

So, complications and WatchOS 2. I've never really managed to crack these.


I'm trying to achieve something fairly simple and build it up from there. I'm using objective C so and help would be preferable on that but could work it out from swift if I had to. For now let's just say my complication data is just something really simple like the time, except the data must come from the iPhone. I'd like my complication to update every 30 mins.

Ideally I would call transferCurrentComplicationUserInfo


From the iPhone however I do not believe is is possible to schedule the iPhone to wake every 30 mins in the background to do this so that rules that out.

So for scheduled updates it has to start with the ComplicationController and GetNextRequestedUpdateDate

I can set this to time interval 3600 seconds (30 mins) and jobs a gooden in 30 mins it wakes and calls RequestedUpdateDidBegin

So, how do I then get the time data from my iPhone?


Let's assume it's nearby and I've got plenty of 'budget' for updating the complication.

I thought I could use OpenParentApplication

But that will apparently only work when called from inside the interfaceController class, that would involve the user having to open the complication to update the app so scrap that.


Next is using WatchConnectivity and using either the updateApplicationContext or sendMessage options. I'm not sure exactly how to get these calls to wake the app from background however and the didRecieveMessage or didRecieveApplicationContext never gets called in the ComplicationController so I have to assume I've got something wrong. Because I only call the CLkServer complication update etc.. then, the complication never updates.

I'm fairly sure what I'm trying to achieve is possible, waking the iPhone app when the complication need an update and then obtaining really basic data from the iPhone. I'm just not sure how to implement it.


Any help would be amazing, thanks!

Replies

I think you're initial idea may be the best, you can schedule wakeups on the iPhone, and if you are willing to rely on updates from the phone, then that is usually easier. I believe you can use a local NSNotification to do that. You may need to enable a background mode so the iPhone app is allowed to wakeup in the background.


It really depends on what kind of data you will be using though. If you can perform a web retrieval for your data, the watch can do that directly, without relying on the phone. There are several WWDC videos related to getting data to the watch and also complication setup. This one uses watchconnectivity and the web retrieval technique. https://developer.apple.com/videos/play/wwdc2015-713/


You need to know what the update method is (where your data comes from) to pick the best method to get it to a complication. (Because of the limitations on when you are allowed to wakeup and how you are allowed to transfer data.)

So Ive been unable to work out how to get my iPhone app to wake periodically.

Instead I looked into using sendMessage when the complication updates and then didRecieveMessage in the iOS appdelegate. THe message is recieved by the appdelegate and it replies but the reply is only occasionally recieved by the complication controller. Generally it works the first time and never again.

I even tried from the app delegate, rather than replying, sending a seperate message, no luck.

By the way. All these method work fine if its within the watchOS app rather that the complication.

Complication continue to give me a headache.

sendMessage can only be used when session.reachable is true/YES. The WWDC session that CobraPA linked to above discusses the nuances of reachability, and its behavior in quite a lot of detail. The behavior you are seeing is that sendMessage is available to a complication only in very specific cirtcumstances when the system decides that your complication might be in need of a lot of data (such as when the user first adds it to the clock face). This means you cannot rely on sendMessage for regular updates of the complication. The WWDC talk does discuss the different options of how you can get data to your complication, and has examples of the kind of data suitable for each of the techniques.

Thank you very much, I was getting to this conclusion but a confirmation is great. I actually did review the WWDC talks on someone elses sugestiong and have since been using transferCurrentComplicationUserInfo. I then have didReceiveUserInfo in my complication controller and all works fine.

However, I am currently cheating slightly. I use sendMessage to take the iPhone app in background and then from there use didRecieveUserInfo. Is that bad practice? Is there a better way of doing it? I am aware in the watch connectivity video they suggest you should push updates from the phone rather than pull them from the watch. Im just unaware of how to get the iOS app even when not running every few minutes like it does when the watch uses sendMessage.

Anyway, thanks again.