I need to send different messages from different buttons. How do I use didReceiveMessage
to receive them all?
Asked
Active
Viewed 274 times
1

Seven
- 11
- 1
-
Welcome to SO! Please make an effort to try this yourself, then post your code. Questions asking for tutorials are off-topic. See [ask] for more details. – Mar 25 '16 at 02:11
1 Answers
1
didReceiveMessage
being called
According to Apple:
didReceiveMessage
is called every time a new mesage is received fromWatchConnectivity
on Apple Watch.
You could use its argument to check the message, and you could add an entry to the dictionary passed by WCSession
to check the source. For example if the argument is called message
, you can use the following code:
Swift
switch message["source"] {
case "button1" : print("Source is button 1")
case "button2" : print("Source is button 2")
default : break
}
Objective-C
switch (message[@"source"]){
case @"button1" : NSLog(@"Source is button 1"); break;
case @"button2" : NSLog(@"Source is button 2"); break;
}
So you could use one didReceiveMessage
method to receive all different messages from different buttons.
Conclusion
1- didReceiveMessage
is called every time a message is coming.
2- You could use its argument to check the message.
3- You could use one didReceiveMessage
method to receive all different messages from different buttons.

Seyed Parsa Neshaei
- 3,470
- 18
- 30