Issue Description
In a manner similar to Handoff (
https://wiki.appcelerator.org/display/guides2/Handoff+User+Activities), using the Ti.App.iOS.UserActivity API to implement Universal Links in an app. This was to connect my website with the app. Basically this was to allow Safari users to open thea app via a link on the website.
In the app there is following event handler:
Ti.App.iOS.addEventListener('continueactivity', function(e){
if (e.activityType === 'NSUserActivityTypeBrowsingWeb') {
var url = e.webpageURL;
// Display relevant content
}
});
This would listen for the continueactivity event to be fired by iOS and capture the URL from the UserActivity in the function parameters. Then it would display relevant content based on the URL.
This all worked fine on SDK 5.0.2. But after switching to SDK 5.1.1 it seems as though the 'continueactivity' event is never being fired.
[~rramirez] Can you please provide a more detailed example code to trigger the event? One app.js including a test case would be great!
Can you validate the issue using the following code:
Hello, tried the example code (https://gist.github.com/boarnoah/2e4a0970610b3cd46f1a) The following is the console output: Creating activity... Activity is supported... continueactivity didn't seem to fire This was on ios 9.1, Ti SDK 5.2-5.1.x. Xcode 7.2 (same place as the salesforce ticket). I've attached the example app used (http://www.mediafire.com/download/t2rq265ks3t5cuw/FooBar_1.zip)
[~adipa] Did the example work with 5.0.2? Trying to test it.
@hansknoechel had to [reinstall](https://medium.com/all-titanium/reinstalling-appcelerator-titanium-on-mac-from-scratch-9a2bb6b9b629#.3yp9lwj3o) my AppC Studio, was having node issues when building to 5.0.2. Also had to replace:
with:
.isSupported wasn't defined in 5.0.2 Continue activity still didn't fire from what I can see.
If my provided test case doesn't work, I need a test case that works anyway. As soon as I have that, I can debug and track-down the issue. Thanks guys!
Does anyone know the status of this bug? I can't get continueactivity to fire on universal links.
[~dfoxinator] we've been able to create a working example of continue activity on 5.0.2 on one of our private servers. Will be updating the salesforce ticket tomorrow to let appcelerator test it out on their end which should hopefully bump up this jira ticket as well.
@adipa thank you for the information, I appreciate it. That is good news. This seems like very important functionality that has been broken for quite some time now.
Checking in on this again. Does anyone have any kind of workaround? I have trouble believing more people aren't running into this so I'm wondering if I'm missing something here. But this more or less renders it impossible to link to content in an app if you don't know whether the user has the app installed or not.
I don't think you're missing anything. We're eagerly awaiting a fix.
Damn. I'm guessing maybe you're in the same boat - but it should be noted that there used to be a semi-workaround for this bug in that you could use hacks on the web side in combination with URL schemes to produce very similar behavior to universal links. However, this functionality was removed/rendered unusable in an iOS 9.x release making universal links the only way to accomplish what used to be do-able with just a url scheme.
Hey guys, as said before, I need to have a demo code that worked in 5.0.2 and doesn't work on 5.1.x and above. As soon as I have that, the bugfix should be schedulable.
Okay, so what [~adipa] provided isn't working/sufficient?
Hello [~hansknoechel] we did manage to show a working demo on 5.0.2 that doesn't work on 5.1.x+ to Mr Ricardo Ramirez last week (in connection with the salesforce ticket). I'll ask him to forward you the details.
I can provide the demo and the steps to replicate at 8 PM pacific time
Alright, I have been able to test it using the below code:
and the following inside the tiapp.xml:
and it worked with both 5.0.2 and 5.2.x. It might work because I'm testing it from our titanium_mobile Xcode project inside the repository. That project as all precompile-macros defined, so I'm 90 % sure we missed some macro in 5.1.x that causes parts of the code not to be executed correctly. Leave me some time and I will investigate asap!
Did you try using a https server ?
Thanks Hans, it's much appreciated. Please let me know if there's anything I can provide that would help. Not sure if it means anything Ricardo, but I only tested using an https link too and couldn't get that to work, so maybe that means something but not sure.
Would should it change? Please re-validate with 5.2.0.GA and the above demo provided. It works well for me in any tested cases. Also try running it with
<run-on-main-thread>true</run-on-main-thread>
inside theThis is very weird... I just ran my code that didn't work a week ago and uses a universal link and a continueactivity listener and it seemed to work on 5.2.1 GA and 5.2.0 and 5.1.2. Needless to say, I'm a little baffled right now. I'm wondering if this issue has/had something to do with iOS and maybe was fixed or something. Can anyone else who had this issue while using universal links try it and get it to work now? I feel like I'm going crazy.
Some more information - I've been testing more and I'm only able to get the continueactivity listener to fire in one scenario - when the app is run with LiveView turned on in Appcelerator Studio. When I run the same project in Run mode with LiveView disabled, continueactivity never gets fired when I tap a universal link (it does open the app, but doesn't fire the listener). I'm not sure what this means.
Here is a more detailed guide about how to replicate this:
Create a new Titanium Alloy App
Open the controllers/index.js file
paste the next event handler:
Go to apple developer console
Create a new app id
Enable associated domains
Use the Id you created in the alloy project
Go to the provisioning profiles
Create a new provisioning profile with the created app id
Download and install the profile
Create a new Entitlements.plist file with the next info:
Place the Entitlements.plist file in the root of your Titanium project
Create a new apple-app-site-association file with the next content
Save it as apple-app-site-association with no extension
Place the file in the root of your https server
Run The app on device using the created provisioning profile
After run open safari in your app and go to your server
You should see a banner in the web page, click open
The app should be opened and the info message showed
Ricardo, that's a great list of steps. I have my app set up pretty much exactly the same way. I'm curious, if you do a clean install of your app with LiveView turned on, does continueactivity get fired? I'm able to consistently get it to fire ONLY when I have LiveView enabled.
[~rramirez] I'm very sure you code does not work because of the above described scenario: The Event can only be fired if you have at least one "Ti.App.iOS.createUserActivity()" (see here: https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiApp.m#L976). That's why my above example worked and yours didn't. That was introduced by me for the 5.2.0.GA release because I thought nobody would use the event without at least using "createUserActivity" at least once. So long story short: If my code works, that's exactly what's going on. And: If you have a use case where you would need the event without being able to create an activity, let me know and I update the compile-condition. Thanks guys!
PR: https://github.com/appcelerator/titanium_mobile/pull/7897
Thanks Hans, this definitely has something to do with the issue. I threw your PR changes in, and it almost works entirely as expected (even when not in LiveView). If the app is running in the background, then it works fine and the handler is called properly. However, if the app is closed, and a universal link is tapped, the app opens and the following error occurs, crashing the app: {noformat} [ERROR] : The application has crashed with an uncaught exception 'NSInvalidArgumentException'. [ERROR] : Reason: [ERROR] : -[NSUserActivity unboundBridge:]: unrecognized selector sent to instance 0x14763c580 [ERROR] : Stack trace: [ERROR] : [ERROR] : 0 CoreFoundation 0x0000000181c92e38
[~dfoxinator] Can you show me how you create the universal link? Want to see if we might miss another #ifdef statement. Thanks! P.S.: Feel free to write me on Ti.Slack over the next 2 hours so we can troubleshoot it together.
Tested the fix with the demo code provided by [~hansknoechel] and found an issue. Handing off from
iOS9Device1
toiOS9Device2
: *iOS9Device1:* Activity moved to a different device. *iOS9Device2:* continueactivity was fired. *Logs:*{color:#d04437}[ERROR] : UIAlertController is up and showing an alert. ABORTING showing of modal controller{color}
Handing off fromiOS9Device
toiOS8Device
: *iOS9Device:* Activity moved to a different device. *iOS8Device:* {color:#d04437}App crashes. {color} *Xcode Logs:*Handing off from
iOS8Device
toiOS9Device
: *iOS8Device:* Activity moved to a different device. *iOS9Device:* continueactivity was fired. Tested On: iPhone 6S (9.3.3) Device & iPhone 6 Plus (8.3) Device Mac OSX El Capitan 10.11.6 Ti SDK: 5.4.0.v20160802165655 Appc Studio: 4.7.0.201607250649 Appc NPM: 4.2.7 App CLI: 5.4.0-37 Xcode 7.3 Node v4.4.7So, the "error"
UIAlertController is up and showing an alert. ABORTING showing of modal controller
is only shown, because an alert was already presented so the next one was aborted in the queue automatically. Why it doesn't work from iOS 9 to iOS 8 but from iOS 8 to iOS 9: Sick! I would love to have more logs on that, so I can debug it in Xcode. Thanks man![~hansknoechel] in regards to the app crash from iOS9 to iOS8, no error logs are returned in the studio console, so what I provided above was the iOS8 device's logs from Xcode. *Edit:* Ran the app through CLI with DEBUG=*, here is the complete log of the iOS8 device when attempting to handoff from iOS9:
There doesn't seem to be any explicit errors here (also seen in Studio logs), but it may help you diagnose the problem.