Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19446] iOS9: Support block callback on watchOS 2

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2015-09-25T17:12:09.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.1.0
ComponentsiOS
LabelswatchOS2
ReporterRick Blalock
AssigneeChee Kiat Ng
Created2015-09-01T13:17:58.000+0000
Updated2015-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.

Comments

  1. Hans Knöchel 2015-09-02

    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
  2. Chee Kiat Ng 2015-09-14

    PR here: https://github.com/appcelerator/titanium_mobile/pull/7179

    sample code to send message with block function

           Ti.WatchSession.sendMessage({
               message: {
                   message: 'Hi',
                   from: 'app',
                   type: 'message'           
               },
               onReply: function(e) {
                   eventsArea.value += '\nreceive immediate message reply '
                   + '\n' + JSON.stringify(e);           
               }
           });
       
    To see complete implementation on watch <-> titanium app, see https://github.com/cheekiatng/Titanium-WatchOS2-Sample-App/tree/replyHandler
  3. Hans Knöchel 2015-09-25

    PR approved, thank you!
  4. Harry Bryant 2015-11-09

    Verified fixed, however in order for the sample code to work correctly, onReply was changed to reply. 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 as reply : 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 production
  5. Fokke Zandbergen 2015-12-04

    The 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?
  6. Fokke Zandbergen 2015-12-04

    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:
       var message = {
       	foo: 'bar'
       };
       message.message = message;
       Ti.WatchSession.sendMessage(message);
       

JSON Source