admin管理员组文章数量:1291317
I have an Ionic 3 app and I want to set some variable inside it based on the download link from Playstore.
For example, would set the account variable inside my app to be 4. Is there any way to achieve this?
I have an Ionic 3 app and I want to set some variable inside it based on the download link from Playstore.
For example, http://linktoplaystore./app?account=4
would set the account variable inside my app to be 4. Is there any way to achieve this?
- 4 The only way would be Firebase Dynamic links to achieve this I would say. But the links have to be created somewhere (manually or in code). Take a look at firebase.google./docs/dynamic-links. The Ionic plugin for this is still in beta though: ionicframework./docs/native/firebase-dynamic-links – Alex Commented Aug 20, 2018 at 18:28
- developer.android./training/app-links this might be what you are looking for. – user1496463 Commented Aug 26, 2018 at 11:06
- @Alex is this query resolved? take advantage of losing your points :) – nkshio Commented Aug 27, 2018 at 1:15
5 Answers
Reset to default 2You can do this in code by parsing and defining an array
private urlParameters: Array<any> = [];
if (YOURURLVARIABLE.indexOf("?") > 0) {
let splitURL = document.URL.split("?");
let splitParams = splitURL[1].split("&");
let i: any;
for (i in splitParams){
let singleURLParam = splitParams[i].split('=');
let urlParameter = {
'name': singleURLParam[0],
'value': singleURLParam[1]
};
this.urlParameters.push(urlParameter);
}
}
this.urlParamID = navParams.get('account').value;
I don't think it's possible from the Playstore, but from an external source of your own you could access in app functions via Deeplinks. See https://ionicframework./docs/native/deeplinks/ for more information.
this.deeplinks.route({
'/account/:accountId': AccountPage
}).subscribe(match => {
console.log(match.$args);
}, nomatch => {
console.error('Got a deeplink that didn\'t match', nomatch);
});
Parse link
in JavaScript to get the required value
Code Snippet
var link = "http://linktoplaystore./app?account=4";
var variable = link.split('?')[1].split('=')[1];
Also, you should open an API to send this link from server, so you don't need to push app-update in case of any changes in the link.
Hope it helps!
The only way would be Firebase Dynamic links to achieve this (as stated in my ment earlier).
Dynamic links can survive the app installation process. And because of that, you can use the parameters. But the links have to be created somewhere (manually or in code).
Take a look at https://firebase.google./docs/dynamic-links/. The Ionic plugin for this is still in beta though: https://ionicframework./docs/native/firebase-dynamic-links/
I finally managed to make it work using Firebase Dynamic Links.
After I've setup my app in the Firebase console, I manually created a link which looks like this:
https://myapp.page.link/?link=https://play.google./store/apps/details?id=.ionicframework.myapp?account4
In my Ionic app, I've installed and configured Firebase Dynamic Links
plugin: https://ionicframework./docs/native/firebase-dynamic-links/
Then, inside app.ponent.ts
, after the platform is initialized, I use this code:
firebaseDynamicLinks.onDynamicLink().subscribe((res: any) => {
let link = res;
}, err => {
alert(err);
});
The link will be a JavaScript object that looks like this:
{"deepLink":"https://play.google./store/apps/details?id=.ionicframework.couriermanagerclient1234?account4","clickTimestamp":1535449992657,"minimumAppVersion":0}
From here, I can parse the result and extract the account parameter from inside the deepLink
property
本文标签: javascriptIonic 3 Getting value from PlayStore linkStack Overflow
版权声明:本文标题:javascript - Ionic 3: Getting value from PlayStore link - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741527117a2383537.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论