Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

event not firing for defined config.xml path #29

Closed
theaccordance opened this issue Dec 21, 2015 · 15 comments
Closed

event not firing for defined config.xml path #29

theaccordance opened this issue Dec 21, 2015 · 15 comments

Comments

@theaccordance
Copy link

Having trouble getting events to run when I narrow the scope of the path in the config.xml file and build the app for iOS.

The url that would trigger the event: https://foobar.com/public/#/ResetPassword/1234 where 1234 is a server-generated token.

Currently, the app opens and the event fires if the path url attribute is set to the wildcard: <path url="*" event="ul_ResetPassword" />

If I change the path to what I need it to be in production, url="/public/#/ResetPassword/*", the app will open but the event never fires.

The apple-app-site-association file found on the domain:

{
    "applinks": {
        "apps": [],
        "details": [
            {
                "appID": "redacted",
                "paths": [
                    "/public/#/ResetPassword/*"
                ]
            }
        ]
    }
}

My JS code subscribing to the event in my Ionic app:

window.universalLinks.subscribe('ul_ResetPassword', dispatch);
@nikDemyankov
Copy link
Member

Understood, will look into that.

@nikDemyankov
Copy link
Member

As I thought, the problem is with the #. How matching is performed: it takes path component of the url and matches it to the ones, that in config.xml. And path component for https://foobar.com/public/#/ResetPassword/1234 will be just /public/: hash and query parameters are ignored.

Didn't think that in config.xml someone would use query/hash parameters. Will think of something to handle that.

In the meantime, you can do the following:

  1. Leave your config.xml as it is. Something like:

    <universal-links>
      <host name="foobar.com">
        <path url="/public/#/ResetPassword/*" />
      </host>
    </universal-links>

    Leave or remove event property from the <path />, doesn't matter.

  2. In JS code subscribe like so:

    universalLinks.subscribe(null, myHandler);
  3. And then implement the handler, which will check the hash property of the event:

    myHandler: function(eventData) {
      var hash = eventData.hash;
      // check if hash holds /ResetPassword/1234 and handle it
    }

@theaccordance
Copy link
Author

The hash in the URL is because our web application is built on Angular.js, so our routing is actually done on the client-side in the browser.

Your solution looks like it works, so thanks! Curious, do you think this enhancement may make it into the next release? It'll probably be 4-6 weeks before I look to add another path to the configuration for UL; ideally I want to integrate these paths one at a time.

@nikDemyankov
Copy link
Member

Think so, depends on a free time I'll have.

But even if I'm not - you can still just add new <path /> records with event names, and add additional processing in myHandler function. But from it - call appropriate methods (i.e. handlePasswordReset(eventData), handleSomethingElse(eventData) and so on).

As soon as feature is implemented - it will require minimum change in the code: just remove myHandler function and add needed set of calls universalLinks.subscribe('eventName', handler).

@theaccordance
Copy link
Author

Oh really? Okay, it wouldn't be too difficult on my end to construct a handler in the interim if need be. Thanks!

@diegobill
Copy link

👍

@diegobill
Copy link

My implementation only works when I try to access a url like this "https://foobar.com/public/%23/ResetPassword/1234"

%23 is # escaped

@theaccordance , Is this link (https://foobar.com/public/#/ResetPassword/1234) works for you? It opens the app?

@fintis
Copy link

fintis commented Jun 8, 2016

Hi ,
Interesting plugin and I do think it has great potential especially since the giants are beginning to index mobile app contents. Well done!

I do have a small issue though. Following the instructions, I was able to install and configure the plugin successfully. I sent an email to my android device and clicked on the link, my app was launched. Hooray! However, I couldn't get the events to fire... I do not see any console logs etc.

Does this matter that my app is an ionic app? Is there a full working example to see how things are setup? Any advice would be greatly appreciated. As advised I added and index.js file with the following contents:

var app = {
  // Application Constructor
  initialize: function () {
    this.bindEvents();
  },

  // Bind Event Listeners
  bindEvents: function () {
    document.addEventListener('deviceready', this.onDeviceReady, false);
  },

  // deviceready Event Handler
  onDeviceReady: function () {
    console.log('Handle [deviceready] event if you need');
    universalLinks.subscribe('openStarrNotificationPage', app.onStarrNotificationPageRequested);
    universalLinks.subscribe('openVipNotificationPage', app.onVipNotificationPageRequested);
    universalLinks.subscribe('openJobReviewPage', app.onJobReviewPageRequested);
    universalLinks.subscribe('openWorkOrderDetailPage', app.onWorkOrderDetailPageRequested);
    universalLinks.subscribe('launchedAppFromLink', app.onApplicationDidLaunchFromLink);
  },

  onStarrNotificationPageRequested: function (eventData) {
    console.log('Showing starr notification ', eventData);
    // do some work to show list of news
  },

  onVipNotificationPageRequested: function (eventData) {
    console.log('Showing vip notification ', eventData);
    // do some work to show detailed page
  },
  onJobReviewPageRequested: function (eventData) {
    console.log('Showing job reviews ', eventData);
    // do some work to show detailed page
  },
  onWorkOrderDetailPageRequested: function (eventData) {
    console.log('Showing work_order detail ', eventData);
    // do some work to show detailed page
  },

  // launchedAppFromLink Event Handler
  onApplicationDidLaunchFromLink: function (eventData) {
    console.log('Did launch app from the link: ' + eventData.url);
  }
};

app.initialize();

I also have in my config.xml the following relevant content

<universal-links>
    <ios-team-id value="3VJD6U4MGY" />
    <host name="m.myservicecity.com" scheme="https"/>
    <path url="/starr_notification/" event="openStarrNotificationPage" />
    <path url="/job_review/" event="openJobReviewPage" />
    <path url="/vip_notification/" event="openVipNotificationPage" />
    <path url="/work_order/*" event="openWorkOrderDetailPage" />
    <path url="*" event="launchedAppFromLink" />
  </universal-links>

Does the addition of the below code specific for android as a hack to fix a flicker issue matter? I have added an entry that creates an intent-filter...

<platform name="android">
    --- other android specific config---
    <config-file target="AndroidManifest.xml" parent="application">
      <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustPan">
        <intent-filter android:label="@string/launcher_name">
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
    </config-file>
--- other android specific config---
  </platform>

Any help on this is greatly appreciated. I have also tried bootstrapping the events in the run function in the ionic app and still not events are fired!

Cheers

@nikDemyankov
Copy link
Member

Hi @fintis ,

I think the problem is with your configuration in config.xml. It should be:

<universal-links>
    <ios-team-id value="3VJD6U4MGY" />
    <host name="m.myservicecity.com" scheme="https">
      <path url="/starr_notification/" event="openStarrNotificationPage" />
      <path url="/job_review/" event="openJobReviewPage" />
      <path url="/vip_notification/" event="openVipNotificationPage" />
      <path url="/work_order/*" event="openWorkOrderDetailPage" />
      <path url="*" event="launchedAppFromLink" />
    </host>
  </universal-links>

You need to put <path /> tags inside <host /> tag. In your case - they are not in it.

@fintis
Copy link

fintis commented Jun 8, 2016

Hi @nikDemyankov

Many thanks for your prompt response...

Silly me! How could I have missed that?

Will give it a try...

Cheers

@fintis
Copy link

fintis commented Jun 8, 2016

@nikDemyankov one more thing, since we are on the topic, Is it absolutely necessary to put the event registering code in the index.js file?

Using ionic I would want access to my $scope and services... So can I do something like register the events in

$ionicPlatform.ready(function(){
    universalLinks.subscribe('openStarrNotificationPage', onStarrNotificationPageRequested);
    universalLinks.subscribe('openVipNotificationPage', onVipNotificationPageRequested);
    universalLinks.subscribe('openJobReviewPage', onJobReviewPageRequested);
    universalLinks.subscribe('openWorkOrderDetailPage', onWorkOrderDetailPageRequested);
    universalLinks.subscribe('launchedAppFromLink', onApplicationDidLaunchFromLink);
})

And in the run function i declare the event firing like this

angularmodule.run(function(){
//other code
onStarrNotificationPageRequested: function (eventData) {
    console.log('Showing starr notification ', eventData);
    // do some work to show list of news
  },

  onVipNotificationPageRequested: function (eventData) {
    console.log('Showing vip notification ', eventData);
    // do some work to show detailed page
  },
  onJobReviewPageRequested: function (eventData) {
    console.log('Showing job reviews ', eventData);
    // do some work to show detailed page
  },
  onWorkOrderDetailPageRequested: function (eventData) {
    console.log('Showing work_order detail ', eventData);
    // do some work to show detailed page
  },

  // launchedAppFromLink Event Handler
  onApplicationDidLaunchFromLink: function (eventData) {
    console.log('Did launch app from the link: ' + eventData.url);
  }
})

Cheers

@nikDemyankov
Copy link
Member

@fintis you can subscribe at any time you want and at any place. The only requirement is that universalLinks module should be accessible and defined. Otherwise you'll get undefined error.

@fintis
Copy link

fintis commented Jun 8, 2016

@nikDemyankov Thanks for this awesome plugin +1

@nikDemyankov
Copy link
Member

Thanks :)

@nordnet-deprecation-bot
Copy link
Contributor

👋 Hi! Thank you for your interest in this repo.

😢 We are not using nordnet/cordova-universal-links-plugin anymore, and we lack the manpower and the experience needed to maintain it. We are aware of the inconveniece that this may cause you. Feel free to use it as is, or create your own fork.

🔒 This will now be closed & locked.

ℹ️ Please see #160 for more information.

@nordnet nordnet locked and limited conversation to collaborators Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants