2

I want to make the interface controller check to make sure it is still in the foreground when I get a reply from the phone. If it is, perform a haptic to let the user know it finished working.

sendMessage:replyHandler: is what I am using to communicate to the phone, but it can take a long time to return. The InterfaceController is set up to be the WCSessionDelegate. It can take long enough that the user could lower their wrist before completion. In that case, I want to trap the haptic not to fire. As of now, the haptic can queue up and then play at a random time in the future, which is not helpful.

I have configured a notification to be sent, but that only displays if the watch isn't showing the app. Hence why I need to figure out of the interfacecontroller is on screen before trying to play the haptic.

Charlie
  • 1,279
  • 2
  • 12
  • 28

2 Answers2

0

I'd first think to look into improving the iOS code, so it doesn't take as long to return a reply.

However you can include the current date in the reply message, then have the reply handler check to see if the reply was immediate before playing the haptic. This would avoid it from playing in the future if the reply was handled when your app next became active.

By the way, the interface controller would be on-screen, since it is executing the reply handler.

  • This answer helps me understand ways to improve beyond solving my problem, and addresses my problem as well. Thank you! Strangely even when the controller isn't on screen it'd execute the haptic but i think that is because it is being called within a closure and I didn't put it on the main queue. Regardless, your date timeIntervalSinceNow from the reply will solve the problem. – Charlie Apr 21 '16 at 15:33
-1

Steps that I would suggest.

  1. sendMessage:replyHandler: from Watch to send Task request, that will ask the phone to perform some long running task.
  2. On watch with this Call make some BOOL, let's say shouldUpdatePhone = YES
  3. Now consider that your task is running and Watch is going InActive, in that case, your Flag (shouldUpdatePhone) is YES so just again make the immediate call and tell iPhone that Screen is now inActive.
  4. If the long running task is completed after that time you will have information that Watch is now inactive then avoid the response signal of Haptic.
Mrug
  • 4,963
  • 2
  • 31
  • 53
  • 1
    Why is this downvoted? Seems reasonable enough. I know that bool flags are generally considered to be a buggy way to code, but this sounds simple, am I missing something? – Charlie Apr 21 '16 at 15:15