Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20535] iOS: Ti.WatchSession.sendMessage "message cannot be nil"

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-03-09T22:20:28.000+0000
Affected Version/sRelease 5.2.0
Fix Version/sRelease 5.4.0
ComponentsiOS
Labelsios, qe-5.4.0, watchOS2, watchkit
ReporterRick Blalock
AssigneeHans Knöchel
Created2016-03-09T03:27:29.000+0000
Updated2016-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

Comments

  1. Rick Blalock 2016-03-09

    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:
       					Ti.WatchSession.sendMessage({
       						message: {
       							favorites: arr
       						}
       					});
       
  2. Rick Blalock 2016-03-09

    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
  3. Chee Kiat Ng 2016-03-09

    [~hansknoechel] take a look? should be a docs issue.
  4. Hans Knöchel 2016-03-09

    [~rblalock] Looking through the [docs](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.WatchSession-method-sendMessage), the message property is available. We could add the required flag and a note, that the property is required. -In addition to that, it looks like our API expects the callback as onReply, but the docs say reply. I'd actually prefer the reply naming, since it's the same with success, error, cancel callback's in other API's (so without the alloy-style on). 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!
  5. Hans Knöchel 2016-03-09

    We should also update the sample app [here](https://github.com/appcelerator-developer-relations/appc-sample-watchos2/blob/master/app/controllers/watchsession.js).
  6. Hans Knöchel 2016-03-09

    PR: https://github.com/appcelerator/titanium_mobile/pull/7819
  7. Harry Bryant 2016-08-05

    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.*

JSON Source