Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Last active August 29, 2015 14:20
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/0c9cfcd816fbd718fb08 to your computer and use it in GitHub Desktop.
Save benbahrenburg/0c9cfcd816fbd718fb08 to your computer and use it in GitHub Desktop.
TIMOB-18854 : Add Delegate & Reply for openParentApplication to Titanium

This pull request adds support for a Apple Watch Extension to be able to openParentApplication and have a Titanium application reply.

This pull request is related to the Jira ticket TIMOB-18854.

This pull request consists of a few different parts.

1.Application Delegate

This pull request adds a delegate method to Tiapp.m this delegate raises the Ti.App.iOS watchkitextensionrequest event. The userInfo provided by the extension openParentApplication is passed through to the watchkitextensionrequest event. The reply method of the delegate is captured and placed into an NSDictionary. This allows for the reply message to later be called as part of the sendWatchExtensionReply method.

2.The Ti.App.iOS event

This is the coordinator for all of the actions done within your Titanium application. The callback returns two properties, handlerId and userInfo (optional). The handlerId is the most important component in that it is the key to our NSDictionary with the reply block that needs to be called. The userInfo is optional, and includes the information passed from your WatchKit extension.

Ti.App.iOS.addEventListener("watchkitextensionrequest",function(e){

});

3.sendWatchExtensionReply

The sendWatchExtensionReply method is used to trigger the reply method from the delegate. This must be called or bad things happen. The sendWatchExtensionReply method has a required paramater of the handlerId, and an optional payload to return to the watch extension. The optional payload must be an object, not an array. If you need to pass an array, you must do so as a property of an object.

Example with all paramters

Ti.App.iOS.addEventListener("watchkitextensionrequest",function(e){
    var myReplyContent = {foo:"bar"};
    Ti.App.iOS.sendWatchExtensionReply(e.handlerId,myReplyContent);
});

Example with only handlerid

Ti.App.iOS.addEventListener("watchkitextensionrequest",function(e){
    Ti.App.iOS.sendWatchExtensionReply(e.handlerId);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment