Reputation: 219
I am using watchOS 2
and Xcode 7.3
. I have 3 interface controllers(IC) in watch app. I am sending messages to these 3 ICs from AppDelegate in 3 different scenerios using "[WCSession defaultSession] sendMessage"
method. The receiving method is provided in all 3 ICs. But the message is received mostly in the 3rd IC. What should I do to receive the message in the particular IC.
Upvotes: 0
Views: 175
Reputation: 219
Give the didReceiveMessage method in ExtensionDelegate.m in the watch app extension. Pass the name of the interface controller to which the message is intended in the sendMessage method. In if-else condition, call the method in the intended interface controller using notification centre.
Upvotes: 0
Reputation: 778
You can check for the keys of your dictionary that you send. You can use three different keys and then check whether it is the right key for the right interface controller.
Upvotes: 1
Reputation: 4666
I would suggest some re-architecting as right now you have your interface controllers doing "networking" and model work.
My recommended approach would be to create a "persistence manager" that is the WCSession delegate. Any data that is received is persisted, and then using an observer or notification pattern other parts of your code is informed of the change. They will then go ahead and re-run any data queries and update their UI if anything related to the UI they are presenting has been updated (add new entries to a table row, new item was favorited, etc).
This has many advantages such as reduced complexity in the interface controllers, better separation of concerns; but perhaps most importantly it enables your extension to run in the background (where no interface controllers are visible) yet be able to receive data, persist it and then take advantage of it next time the application is launched.
Upvotes: 2