iosiphoneuilocalnotificationapple-watchwcsession

Call didReceiveApplicationContext while device is asleep?


When I click a button in my apple watch app, I want to cancel a local notification that was scheduled by the iPhone app.

Right now, I'm sending information using the updateApplicationContext method to transfer info between the watch and the phone, and I cancel my local notifications through the didReceiveApplicationContext method.

Right now, didReceiveApplicationContext only gets called when the app is open. That means that the notification still appears if I haven't opened the app in the meantime. I need to make sure the notification doesn't appear even if I don't open the app.

Is there any way to call didReceiveApplicationContext in the background while the device is asleep or the app is not in the foreground?


Solution

  • No, for this you will have to check if the WatchKit extension's WCSession's reachable property is true/YES, and if it is use the one of the sendMessage APIs as these can wake the iOS app up in the background.