Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20220] iOS: Ti.App.iOS.continueactivity not being fired

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-04-01T20:16:30.000+0000
Affected Version/sRelease 5.1.1
Fix Version/sRelease 5.4.0
ComponentsiOS
Labelsqe-5.4.0
Reporter Ricardo Ramirez
AssigneeHans Knöchel
Created2016-01-11T22:03:14.000+0000
Updated2016-08-08T21:45:48.000+0000

Description

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.

Comments

  1. Hans Knöchel 2016-01-30

    [~rramirez] Can you please provide a more detailed example code to trigger the event? One app.js including a test case would be great!
  2. Hans Knöchel 2016-02-28

    Can you validate the issue using the following code:
       var activity =  Ti.App.iOS.createUserActivity({
           activityType:'com.foo.message',
           title:'Handoff Messenger',
           userInfo:{
               msg: 'Tag! You\'re it!'
           }
       });
       
       if(!activity.isSupported()){
           alert('activity is not supported');
       } else {
           activity.becomeCurrent();
       }
       
       activity.addEventListener('useractivitywascontinued', function(e) {
           Ti.API.info('Activity moved to a different device.');
       });
       
       Ti.App.iOS.addEventListener('continueactivity', function(e){
           if (e.activityType === 'com.foo.message' && e.userInfo.msg) {
               alert(e.userInfo.msg);
           }
       });
       
       /** -- tiapp.xml --
       
       <ios>
       	<plist>
       		<dict>
       		<key>NSUserActivityTypes</key>
       		<array>
       			<string>com.foo.message</string>
       			<string>com.foo.bar</string>
       		</array>
       		</dict>
       	</plist>
       </ios>
       
       **/
       
  3. Adipa Wijayathilaka 2016-02-29

    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)
  4. Hans Knöchel 2016-03-08

    [~adipa] Did the example work with 5.0.2? Trying to test it.
  5. Adipa Wijayathilaka 2016-03-08

    @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:
       if(!activity.isSupported()){
           alert('activity is not supported');
       } else {
           activity.becomeCurrent();
       }
       
    with:
       activity.becomeCurrent();
       
    .isSupported wasn't defined in 5.0.2 Continue activity still didn't fire from what I can see.
  6. Hans Knöchel 2016-03-10

    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!
  7. David Fox 2016-03-23

    Does anyone know the status of this bug? I can't get continueactivity to fire on universal links.
  8. Adipa Wijayathilaka 2016-03-23

    [~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.
  9. David Fox 2016-03-23

    @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.
  10. David Fox 2016-03-30

    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.
  11. Alex Bernier 2016-03-30

    I don't think you're missing anything. We're eagerly awaiting a fix.
  12. David Fox 2016-03-30

    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.
  13. Hans Knöchel 2016-03-30

    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.
  14. Alex Bernier 2016-03-30

    Okay, so what [~adipa] provided isn't working/sufficient?
  15. Adipa Wijayathilaka 2016-03-30

    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.
  16. Ricardo Ramirez 2016-03-30

    I can provide the demo and the steps to replicate at 8 PM pacific time
  17. Hans Knöchel 2016-03-30

    Alright, I have been able to test it using the below code:
        Ti.API.info("Creating activity...");
        var win = Ti.UI.createWindow();
        win.add(Ti.UI.createLabel({text: "Check logs",color: "white"}))
        var activity =  Ti.App.iOS.createUserActivity({
            activityType:'com.foo.message',
            title:'Handoff Messenger',
            userInfo:{
                msg: 'Tag! You\'re it!'
            }
        });
        
        
        //if(!activity.isSupported()){
        //    alert('activity is not supported');
        //} else {
        	Ti.API.info("Activity is supported...");
            activity.becomeCurrent();
        //}
        
        activity.addEventListener('useractivitywascontinued', function(e) {
            alert('Activity moved to a different device.');
        });
        
        Ti.App.iOS.addEventListener('continueactivity', function(e){
            alert("continueactivity was fired");
            if (e.activityType === 'com.foo.message' && e.userInfo.msg) {
                alert(e.userInfo.msg);
            }
        });
        
        win.open();
        
    and the following inside the tiapp.xml:
        <ios>
            <plist>
                <dict>
                    <key>NSUserActivityTypes</key>
                    <array>
        		<string>com.foo.message</string>
        		<string>com.foo.bar</string>
        	    </array>
                </dict>
            </plist>
        </ios>
        
    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!
  18. Ricardo Ramirez 2016-03-30

    Did you try using a https server ?
  19. David Fox 2016-03-30

    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.
  20. Hans Knöchel 2016-03-30

    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 the section ( not ) to see possible differences.
  21. David Fox 2016-03-30

    This 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.
  22. David Fox 2016-03-31

    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.
  23. Ricardo Ramirez 2016-03-31

    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:

        Ti.App.iOS.addEventListener('continueactivity', function(e){ 
             if (e.activityType === 'NSUserActivityTypeBrowsingWeb') { 
                  var url = e.webpageURL; 
                  Ti.API.info(url);
             } 
        }); 
        

    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:

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
        <dict>
        	<key>get-task-allow</key>
        	<true/>
        	<key>com.apple.developer.associated-domains</key>
        	<array>
        		<string>applinks:PLACEHEREYOURHTTPSDOMAIN</string>
        	</array>	
        	<key>aps-environment</key>
        	<string>development</string>
        	<key>application-identifier</key>
        	<string>PLACEHEREYOURAPPIDNUMBER.PLACEHEREYOURAPPID</string>
        	<key>keychain-access-groups</key>
        	<array>
        		<string>PLACEHEREYOURAPPIDNUMBER.PLACEHEREYOURAPPID</string>
        	</array>
        </dict>
        </plist>
        

    Place the Entitlements.plist file in the root of your Titanium project

    Create a new apple-app-site-association file with the next content

        {
            "applinks": {
                "apps": [],
                "details": [
                    {
                        "appID": "PLACEHEREYOURHTTPSDOMAIN",
                        "paths": [ "*" ]
                    }
                ]
            }
        }
        

    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

  24. David Fox 2016-03-31

    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.
  25. Hans Knöchel 2016-03-31

    [~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!
  26. Hans Knöchel 2016-03-31

    PR: https://github.com/appcelerator/titanium_mobile/pull/7897
  27. David Fox 2016-03-31

    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 + 124 [ERROR] : 1 libobjc.A.dylib 0x00000001812f7f80 objc_exception_throw + 56 [ERROR] : 2 CoreFoundation 0x0000000181c99ccc + 0 [ERROR] : 3 CoreFoundation 0x0000000181c96c74 + 872 [ERROR] : 4 CoreFoundation 0x0000000181b94d1c _CF_forwarding_prep_0 + 92 [ERROR] : 5 myapp 0x00000001000a0200 myapp + 98816 [ERROR] : 6 myapp 0x00000001000ad120 myapp + 151840 [ERROR] : 7 myapp 0x000000010036a2e4 myapp + 3023588 [ERROR] : 8 myapp 0x00000001004ffab0 myapp + 4684464 [ERROR] : 9 myapp 0x00000001005018f0 myapp + 4692208 [ERROR] : 10 myapp 0x00000001004169bc myapp + 3729852 [ERROR] : 11 myapp 0x0000000100418e78 myapp + 3739256 [ERROR] : 12 myapp 0x0000000100417ab8 myapp + 3734200 [ERROR] : 13 myapp 0x0000000100318084 myapp + 2687108 [ERROR] : 14 myapp 0x0000000100317d28 myapp + 2686248 [ERROR] : 15 myapp 0x0000000100368c10 myapp + 3017744 [ERROR] : 16 myapp 0x00000001000a6728 myapp + 124712 [ERROR] : 17 myapp 0x00000001000a7568 myapp + 128360 [ERROR] : 18 Foundation 0x0000000182667e1c + 1000 [ERROR] : 19 libsystem_pthread.dylib 0x00000001818f7b28 + 156 [ERROR] : 20 libsystem_pthread.dylib 0x00000001818f7a8c + 0 [ERROR] : 21 libsystem_pthread.dylib 0x00000001818f5028 thread_start + 4 [ERROR] : *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSUserActivity unboundBridge:]: unrecognized selector sent to instance 0x14763c580' [ERROR] : *** First throw call stack: [ERROR] : (0x181c92e38 0x1812f7f80 0x181c99ccc 0x181c96c74 0x181b94d1c 0x1000a0200 0x1000ad120 0x10036a2e4 0x1004ffab0 0x1005018f0 0x1004169bc 0x100418e78 0x100417ab8 0x100318084 0x100317d28 0x100368c10 0x1000a6728 0x1000a7568 0x182667e1c 0x1818f7b28 0x1818f7a8c 0x1818f5028) {noformat}
  28. Hans Knöchel 2016-03-31

    [~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.
  29. David Fox 2016-03-31

  30. Harry Bryant 2016-08-04

    Tested the fix with the demo code provided by [~hansknoechel] and found an issue. Handing off from iOS9Device1 to iOS9Device2: *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 from iOS9Device to iOS8Device: *iOS9Device:* Activity moved to a different device. *iOS8Device:* {color:#d04437}App crashes. {color} *Xcode Logs:*
        Aug  4 15:31:23 Spam kernel[0] <Notice>: xpcproxy[1079] Container: /private/var/mobile/Containers/Data/Application/326B7AB3-16DB-4C33-94A6-B8BC41EF6A71 (sandbox)
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>: SOASTA TouchTest Build : 8244.160
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>: SOASTA TouchTest initializing...
        Aug  4 15:31:23 Spam locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>: Process delegate TiApp(o) : TiHost : NSObject
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>:   added ctDidFinishLaunchingWithOptions
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>:   watching application:didFinishLaunchingWithOptions: : success
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>:   added ctOpenURL
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>:   watching openURL : success
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>: SOASTA TouchTest initialized in 103 msec (#51)
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Error>: assertion failed: 12D508: libxpc.dylib + 71792 [3C982BC2-5B46-305A-9A09-3C3D15332820]: 0x7d
        Aug  4 15:31:23 Spam Unknown[1079] <Error>: 
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>: [DEBUG] Reading stylesheet from: /private/var/mobile/Containers/Bundle/Application/9A54667A-1524-4020-B04D-7E23BBB19F46/SamusTheBold.app/stylesheet.plist
        Aug  4 15:31:23 Spam SamusTheBold[1079] <Warning>: [INFO] SamusTheBold/1.0 (5.4.0.16921ce)
        Aug  4 15:31:23 Spam sharingd[59] <Notice>: 15:31:23.340 : Requesting Handoff payload
        Aug  4 15:31:23 Spam sharingd[59] <Notice>: 15:31:23.643 : Received a new Handoff advertisement from "SAMWISE"
        Aug  4 15:31:23 Spam sharingd[59] <Warning>: [Warning] No delegate was registered that could handle protobuf BC060AC5-021F-4A2D-883F-5FDA9A177137
        Aug  4 15:31:23 Spam sharingd[59] <Warning>: [Warning] No delegate was registered that could handle protobuf BC060AC5-021F-4A2D-883F-5FDA9A177137
        Aug  4 15:31:23 Spam sharingd[59] <Notice>: 15:31:23.719 : Received requested Handoff payload from "SAMWISE" ((null))
        Aug  4 15:31:23 Spam ReportCrash[1080] <Error>: task_set_exception_ports(B07, 400, D03, 0, 0) failed with error (4: (os/kern) invalid argument)
        Aug  4 15:31:23 Spam ReportCrash[1080] <Notice>: ReportCrash acting against PID 1079
        Aug  4 15:31:23 Spam ReportCrash[1080] <Notice>: Formulating crash report for process SamusTheBold[1079]
        Aug  4 15:31:23 Spam SpringBoard[53] <Warning>: BSXPCMessage received error for message: Connection invalid
        Aug  4 15:31:23 Spam mediaserverd[22] <Notice>: '' com.appc.SamusTheBold(pid = 1079) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None
        Aug  4 15:31:23 Spam com.apple.xpc.launchd[1] (UIKitApplication:com.appc.SamusTheBold[0xbad1][1079]) <Notice>: Service exited due to signal: Segmentation fault: 11
        Aug  4 15:31:23 Spam SpringBoard[53] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application.
        Aug  4 15:31:23 Spam SpringBoard[53] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application.
        Aug  4 15:31:23 Spam mediaserverd[22] <Notice>: 'FigPlayer - 29' (pid = 29) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None
        Aug  4 15:31:23 Spam ReportCrash[1080] <Notice>: Saved report to /var/mobile/Library/Logs/CrashReporter/SamusTheBold_2016-08-04-153123_Spam.ips
        Aug  4 15:31:23 Spam SpringBoard[53] <Warning>: Application 'UIKitApplication:com.appc.SamusTheBold[0xbad1]' crashed.
        Aug  4 15:31:23 Spam assertiond[63] <Warning>: pid_suspend failed for <BKNewProcess: 0x154e16170; com.appc.SamusTheBold; pid: 1079; hostpid: -1>: Unknown error: -1, Unknown error: -1
        Aug  4 15:31:23 Spam assertiond[63] <Warning>: Could not set priority of <BKNewProcess: 0x154e16170; com.appc.SamusTheBold; pid: 1079; hostpid: -1> to 2, priority: No such process
        Aug  4 15:31:23 Spam assertiond[63] <Warning>: Could not set priority of <BKNewProcess: 0x154e16170; com.appc.SamusTheBold; pid: 1079; hostpid: -1> to 4096, priority: No such process
        Aug  4 15:31:23 Spam SpringBoard[53] <Warning>: Unable to deliver -[UIRemoteApplication showTopMostMiniAlertWithSynchronizationPort:] message to port 0: (ipc/send) invalid destination port
        Aug  4 15:31:23 Spam sharingd[59] <Notice>: 15:31:23.896 : Stopping Handoff scanning
        
    Handing off from iOS8Device to iOS9Device: *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.7
  31. Chee Kiat Ng 2016-08-05

  32. Hans Knöchel 2016-08-05

    So, 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!
  33. Harry Bryant 2016-08-05

    [~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:
        [INFO]  SOASTA TouchTest Build : 8244.160
        [INFO]  SOASTA TouchTest initializing...
        [INFO]  Process delegate TiApp(o) : TiHost : NSObject
        [INFO]    added ctDidFinishLaunchingWithOptions
        [INFO]    watching application:didFinishLaunchingWithOptions: : success
        [INFO]    added ctOpenURL
        [INFO]    watching openURL : success
        [INFO]  SOASTA TouchTest initialized in 92 msec (#51)
        [INFO]  assertion failed: 12D508: libxpc.dylib + 71792 [3C982BC2-5B46-305A-9A09-3C3D15332820]: 0x7d
        [DEBUG] Reading stylesheet from: /private/var/mobile/Containers/Bundle/Application/6BE24824-4B19-4501-9105-C2AAD2348AE0/SamusTheBold.app/stylesheet.plist
        [INFO]  SamusTheBold/1.0 (5.4.0.16921ce)
        
    There doesn't seem to be any explicit errors here (also seen in Studio logs), but it may help you diagnose the problem.
  34. Harry Bryant 2016-08-08

JSON Source