UpdateApplicationContext Not Receiving updates

Hi community. It's my first time trying WatchConnectivity kit. When I attempt to send ApplicationContext from phone, my debug print indicates that updateApplicationContext is working correctly. However, I'm having trouble receiving it form the paired watch simulator as nothing is shown on that end. Here are the code for the Phone Extension:


    func sendDataToWatch(data: String) {

        state.append(data)

        do {

            NSLog("sent by phone")

            try WCSession.default.updateApplicationContext(["currentstate": state])

        }

        catch {

            print(error)

        }

    }

Here are the code for watch:

func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String: Any]) {

        print("Hello")

        if let getState = applicationContext["currentstate"] as? [String]{

            print("\(getState)")

            self.state = getState[0]

        }

    }

Any suggestion would be appreciated!

Post not yet marked as solved Up vote post of Gefei Down vote post of Gefei
3.8k views

Replies

Hello. For me this doesn't work on simulators (I do not have a real device to test).

I tried the official sample app about watch connectivity and it doesn't work either.

Updating App Context from Watch to iPhone works fine, but from iPhone to Watch does not.

I've tried it on Xcode 12.5.1 and on Xcode 13 beta 3.

I am also having this issue with Xcode 13 Beta 5.

Same problem here with Xcode 13 and iOS 15 & watchOS 8 simulators. "updateApplicationContext" is not triggering the watch simulator.

Same issue here :( Has anyone found/heard of workarounds?

  • Honestly, I stoped trying. I focused on other things :(

Add a Comment

I am having same problem on Xcode13.3.1, Monterey 12.2.1, Apple M1 Max updateApplicationContext broken and will not send information to the watch simulator for any series of watch simulator. Impossible to work with watch connectivity without physical devices.

Anyone know a workaround?

I'm having this issue with Xcode Version 14.0 beta 4 (14A5284g), but I do see that it updates on the Watch Simulator after I quit and restart the Apple Watch app. It doesn't receive applicationContext while the iPhone simulator and watch simulator are up and running together.

On the iPhone, send the applicationContext on the main queue. On the main queue. It worked fine for me in the simulator.

Same issue here. Running the updatecall on the mainthread did not work for me at least. I've yet to find any way to get this to work.

Same here :(

  • Tested both on Xcode 14 and 13.4

Add a Comment

For testing purposes we can now use: WCSession.default.sendMessage and func session(_ session: WCSession, didReceiveMessage message: [String : Any]). It works on simulator. However, it is very annoying that applicationContext doesn't work.

Add a Comment

I don't know what was the problem but I figured out how to solve it. Basically, you need to recreate the target. In my case, I was using "the old approach" with watchOS app and extension app. Now Xcode 14 offers only a single target - maybe that was the problem. Steps that I used:

  1. Copy all files from your watchOS app to another location.
  2. Delete folder, target, and schemes, remove all remainings from watchOS app.
  3. Add watchOS app target using new Xcode.
  4. Add copied files from step. 1
  5. Configure build settings, signing, and assets (whatever you need).
  6. Very important: set bundle identifier prefixed by your iOS bundle identifier.
  7. Very important: set WKCompanionAppBundleIdentifier in info.plist that equals your iOS app bundle identifier.
  8. Super important: go to your main iOS app target, general tab, frameworks, libraries... and click "+" and add your watchOS app.
  9. Now I like to use first watchOS scheme to install watchOS app first, then change scheme and install iOS app.

Now your apps should be able to communicate using applicationContext.

  • Thanks maxik! I will try your solution and get back to you with any updates : )

  • I tried this on Xcode 13.4 (not on 14 as maxik) and it did not solve the issue to me :(

    I have pending to try it on Xcode 14 with the new single target

Add a Comment

Same issue here. I'm using Xcode 14.0(14A309) release. It worked fine with physical devices. But it failed in watch simulator and iPhone simulator.

  • I'm working at an Apple Watch app for a few months and it is not working since Xcode 13. Works perfectly on device, bot not on simulator.

Add a Comment