Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbahrenburg/7812ae9259b8e06fff10 to your computer and use it in GitHub Desktop.
Save benbahrenburg/7812ae9259b8e06fff10 to your computer and use it in GitHub Desktop.
Exploring how to do openParentApplication in Titanium

This gist outlines how to use an experimental build of the Ti SDK that includes the delegate needed for openParentApplication support

Steps:

  1. Download the latest master nightly build
  2. You need to replace the following four files in your nightly build with the ones listed below

https://github.com/benbahrenburg/titanium_mobile/blob/ca8083c3a99fd017a6656f33f2c99e0d7118c65c/iphone/Classes/TiApp.h https://github.com/benbahrenburg/titanium_mobile/blob/ca8083c3a99fd017a6656f33f2c99e0d7118c65c/iphone/Classes/TiApp.m https://github.com/benbahrenburg/titanium_mobile/blob/ca8083c3a99fd017a6656f33f2c99e0d7118c65c/iphone/Classes/TiAppiOSProxy.m https://github.com/benbahrenburg/titanium_mobile/blob/ca8083c3a99fd017a6656f33f2c99e0d7118c65c/iphone/Classes/TiBase.h https://github.com/benbahrenburg/titanium_mobile/blob/ca8083c3a99fd017a6656f33f2c99e0d7118c65c/iphone/Classes/TiBase.m

  1. Now you are ready to start to test

Testing:

  1. First in your Ti app, you need to add the listener
Ti.App.iOS.addEventListener("watchkitextensionrequest",function(e){

});

This will be fired when your watchkit extension makes a request.

  1. Next you will need to make sure you provide a reply once the event is fired.
Ti.App.iOS.addEventListener("watchkitextensionrequest",function(e){
    var myReplyContent = [{foo:"bar"}];
    Ti.App.iOS.sendWatchExtensionReply(e.handlerId,myReplyContent);
});

This will send the result back to your watch. Bad things will happen if you don't send a reply message. If you don't have any reply content you can just skip that parameter, as soon below.

Ti.App.iOS.addEventListener("watchkitextensionrequest",function(e){
    Ti.App.iOS.sendWatchExtensionReply(e.handlerId);
});

The most important thing to provide is the handlerId that is included within the event callback. This is the reference Titanium needs to issue the reply.

  1. You are now ready to add a WKInterfaceController.openParentApplication statement into your Watch Extension and try it out.

In theory, this should all just work, but I haven't had a chance to test out the full cycle or each of the corners.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment