[TIMOB-19446] iOS9: Support block callback on watchOS 2
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-09-25T17:12:09.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.1.0 |
Components | iOS |
Labels | watchOS2 |
Reporter | Rick Blalock |
Assignee | Chee Kiat Ng |
Created | 2015-09-01T13:17:58.000+0000 |
Updated | 2015-12-04T09:16:34.000+0000 |
Description
Right now, I have to add a session delegate to receive a message back from the device. It took me a little bit to realize this. I was using this: https://developer.apple.com/library/prerelease/watchos/documentation/WatchConnectivity/Reference/WCSession_class/index.html#//apple_ref/occ/instm/WCSession/sendMessage:replyHandler:errorHandler:
Expecting to use the reply block.
The common problem is, that the callback block is called on the device but not using the simulator (the session delegate is called). Reference: https://forums.developer.apple.com/thread/7315
PR here: https://github.com/appcelerator/titanium_mobile/pull/7179
sample code to send message with block function
To see complete implementation on watch <-> titanium app, see https://github.com/cheekiatng/Titanium-WatchOS2-Sample-App/tree/replyHandler
PR approved, thank you!
Verified fixed, however in order for the sample code to work correctly,
onReply
was changed toreply
. After making this change, I was able to send message from device to watch, whereas previously it would cause the Watchkit app to crash. Also verified that the documentation states the correct Callback parameter asreply
: https://docs.appcelerator.com/platform/latest/#!/api/Titanium.WatchSession-method-sendMessage Other than possibly updating the WatchKit Sample App [~cng] I have no issue with the above ticket and am happy to close it. [~hansknoechel] has recommended that we implement a deprecated message for the old sendMessage without Callback, instead of crashing the app without warning. Tested on: iPhone 6S Plus Device & Simulator iOS 9.1, WatchOS 2.0.1. Mac OSX El Capitan 10.11 (15A284) Ti SDK: 5.1.0.v20151104190037 Appc NPM: 4.2.1 Appc CLI: 5.1.0-44 Ti CLI: 5.0.4 Alloy: 1.7.24 Xcode 7.1(7B91b) Node v0.12.7 productionThe documentation is different from the implementation: http://docs.appcelerator.com/platform/latest/#!/api/Titanium.WatchSession-method-sendMessage The documentation says the callback should be passed as the second argument, which I must say I like better then the implementation which changes the first argument into a dictionary that has message and reply: https://github.com/appcelerator/titanium_mobile/blob/bc85170157d3bebc5de1d61a9fe6e34bce84a8c9/iphone/Classes/WatchSessionModule.m#L158-L162 I'll create a ticket to fix the docs, but may I ask why we've chosen this implementation of the what was documented?
The breaking change is done in this commit: https://github.com/appcelerator/titanium_mobile/commit/1d8aee1d2e4862d3d81271aff8ad836b2b09260a#diff-c8e5ac73085caff0252e3086f1c970e3L111 A workaround that works with both Ti 5.0 and 5.1 would be: