I am using WatchConnectivity framework to receive a string from my app. Here is how I send the string in Obj-C from the app:
-(void) viewDidLoad {
//WATCHKIT
WCSession* session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
[self sendInfoToWatch];
}
-(void) sendInfoToWatch {
WCSession* session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
[session sendMessage:@{@"a":@"hello"} replyHandler:^(NSDictionary<NSString *,id> * _Nonnull replyMessage) {
} errorHandler:^(NSError * _Nonnull error) {
}];
}
My Watch app is in Swift. This is how I retrieve the message:
Note: "wc session is supported" works and gets logged to the console
override func willActivate() {
if(WCSession.isSupported()){
NSLog("wc session is supported")
self.session = WCSession.defaultSession()
self.session.delegate = self
self.session.activateSession()
}
super.willActivate()
}
The following function is never called, none of the NSLog's show up, so the QRCodeTitleLabel does not update its text.
func session(session: WCSession, didReceiveMessage message: [String : AnyObject]) {
//recieving message from iphone
QRCodeTitleLabel.setText(message["a"]! as? String)
NSLog("This was called")
NSLog((message["a"]! as? String)!)
}
Does anyone know why this method is not called?
Also, I have imported WatchConnectivity and included WCSessionDelegate after my class name.
Edit:
I added the function with replyHandler, but this method still isn't called:
func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void) {
QRCodeTitleLabel.setText(message["a"]! as? String)
NSLog("This was called")
NSLog((message["a"]! as? String)!)
}