[TIMOB-20535] iOS: Ti.WatchSession.sendMessage "message cannot be nil"
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-03-09T22:20:28.000+0000 |
Affected Version/s | Release 5.2.0 |
Fix Version/s | Release 5.4.0 |
Components | iOS |
Labels | ios, qe-5.4.0, watchOS2, watchkit |
Reporter | Rick Blalock |
Assignee | Hans Knöchel |
Created | 2016-03-09T03:27:29.000+0000 |
Updated | 2016-08-05T22:13:54.000+0000 |
Description
Just now noticing this in the Ti SDK around the watch sendMessage method. Anytime I try to fire the method I get:
[ERROR] Script Error {
[ERROR] column = 48;
[ERROR] line = 517;
[ERROR] message = "-[WCSession sendMessage:replyHandler:errorHandler:]: message cannot be nil.";
[ERROR] sourceURL = "file:///Users/rickblalock/Library/Developer/CoreSimulator/Devices/DD7C8848-C744-4ECD-ADC1-B7A641519F10/data/Containers/Bundle/Application/A7670C9E-9548-4945-8726-E6FB156135B1/Fish%20Rules%20App.app/core.js";
[ERROR] stack = "[native code]\nreceiveWatchMessage@file:///Users/rickblalock/Library/Developer/CoreSimulator/Devices/DD7C8848-C744-4ECD-ADC1-B7A641519F10/data/Containers/Bundle/Application/A7670C9E-9548-4945-8726-E6FB156135B1/Fish%20Rules%20App.app/core.js:517:48";
[ERROR] }
Sample snippet of code:
Ti:
Ti.WatchSession.sendMessage({
favorites: ['some value']
});
Swift (request from the watch to app):
self.session.sendMessage(
["type": "favorites"],
replyHandler: nil,
errorHandler: nil
)
Swift (receiving info from the app to watch):
func session(session: WCSession, didReceiveMessage message: [String : AnyObject]) {
if (message["favorites"] != nil) {
self.favorites = message["favorites"]! as? Array<String>
return;
}
// ... etc
According to the run time error, it's being caused from the Titanium API sendMessage
Ok I figured it out. Back in Sept. the functionality changed. So this is a regression from how it worked before. Per https://github.com/appcelerator/titanium_mobile/blob/0dce6d55b7d3b29cec31e19da6544177f27e1437/iphone/Classes/WatchSessionModule.m#L159 - this works:
Looking at https://github.com/appcelerator/titanium_mobile/commit/1d8aee1d2e4862d3d81271aff8ad836b2b09260a#diff-c8e5ac73085caff0252e3086f1c970e3 - it looks like maybe the docs just need to be updated to point this out eh? This looks intentional, not so much an accidental regression
[~hansknoechel] take a look? should be a docs issue.
[~rblalock] Looking through the [docs](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.WatchSession-method-sendMessage), the
message
property is available. We could add therequired
flag and a note, that the property is required. -In addition to that, it looks like our API expects the callback asonReply
, but the docs sayreply
. I'd actually prefer thereply
naming, since it's the same withsuccess
,error
,cancel
callback's in other API's (so without the alloy-styleon
). What do you guys think? Could deprecate it for 5.4.0 and we clean-up in 6.0.0.- EDIT: Looks like already been changed, great!We should also update the sample app [here](https://github.com/appcelerator-developer-relations/appc-sample-watchos2/blob/master/app/controllers/watchsession.js).
PR: https://github.com/appcelerator/titanium_mobile/pull/7819
Verified as fixed, Tested On: iPhone 6S (9.3.3) Device Watch OS 2.2.2 Mac OSX El Capitan 10.11.6 Ti SDK: 5.4.0.v20160804185318 Appc Studio: 4.7.0.201607250649 Appc NPM: 4.2.7 App CLI: 5.4.0-37 Xcode 7.3.1 Node v4.4.7 *Closing ticket.*