【发布时间】:2020-12-31 06:06:23
【问题描述】:
过去一周我一直在努力弄清楚如何在 Ionic 应用程序中使用 Google Play Install Referrer API。我尝试过使用以下方法:
方法 1:InstallBroadcast
我安装了一个名为cordova-plugin-installreferrer 的cordova 插件和一个npm 模块install-referrer。当我尝试在开发模式下构建应用程序时,我得到的响应是空数组。但是当我在生产模式下构建它时,我得到plugin_not_found 错误。 (PS:我已经在app.module.ts中的providers中添加了)
import { InstallReferrer } from 'install-referrer/ngx';
...
constructor(
private installReferrer: InstallReferrer
) {
this.installReferrer.getReferrer().then(data => {
alert(JSON.stringify(data));
}).catch((err) => {
alert(JSON.stringify(err));
});
}
我还意识到 InstallBroadcast 现在已弃用。我们必须切换到 Play Install Referrer API。
方法 2:Play Install Referrer API
我尝试安装名为cordova-install-referrer-api 的cordova 插件。并尝试了以下代码:
declare var referrer: any;
...
initializeApp() {
try{
referrer.get().then((referrer) => {
alert(JSON.stringify(referrer));
});
}catch(err){
alert(err);
}
...
收到以下错误:ReferenceError: referrer is not defined
请帮助我正确获取推荐人,如果我做错了什么,请告诉我。
【问题讨论】:
标签: cordova ionic-framework ionic4 install-referrer