I have an existing iOS 9.2 and watchOS 2.1 app that uses sendMessage
and transferUserInfo
to send data from the iPhone to the Apple Watch. If sendMessage
fails, I am using transferUserInfo
to queue the data for later delivery:
// *** In the iOS app ***
self.session.sendMessage(message, replyHandler: nil) { (error) -> Void in
// If the message failed to send, queue it up for future transfer
self.session.transferUserInfo(message)
}
// *** In the watchOS app ***
func session(session: WCSession, didReceiveMessage message: [String : AnyObject]) {
// Handle message here
}
func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {
// Handle message here
}
Without changing any code and running the app on iOS 9.3 with watchOS 2.2 on a real device (simulator does not have the same problem), sendMessage
delivers data to the Apple Watch as long as the watch is within range and the screen is on. This is as expected and how it previously worked. However, if the screen is off and sendMessage
fails, transferUserInfo
no longer delivers data to the Apple Watch when the screen turns back on.
In an attempt to find where this was erroring out, I added the following WCSessionDelegate
method to see if the iOS app was failing to send the data:
func session(session: WCSession, didFinishUserInfoTransfer userInfoTransfer: WCSessionUserInfoTransfer, error: NSError?) {
// Called when self.session.transferUserInfo completes
}
This method does get invoked after transferUserInfo
is called, but there is no error returned and the iOS app seems to indicate that the transfer occurred successfully.
At first I thought that perhaps the time it takes to transfer the data has been increased, but after leaving the device alone for a day the data still had not transferred. I am now somewhat suspicious it has something to do with the new multi-watch API, and perhaps the iOS app needs to know a specific watch to send it to, though I only have ever had a single watch paired. Does anyone have any ideas on what might have changed and how to correctly use transferUserInfo
?
transferCurrentComplicationUserInfo:
never seems to successfully transfer a userInfo payload to the watch. It's not until I reboot the watch do things start working again. – Aspergillus