Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cordova 如何在Ionic中使用Google Play安装参考API?_Cordova_Ionic Framework_Ionic4_Install Referrer - Fatal编程技术网

Cordova 如何在Ionic中使用Google Play安装参考API?

Cordova 如何在Ionic中使用Google Play安装参考API?,cordova,ionic-framework,ionic4,install-referrer,Cordova,Ionic Framework,Ionic4,Install Referrer,在过去的一周里,我一直在琢磨如何在一款爱奥尼亚应用程序中使用它。我尝试过使用以下方法: 方法1:InstallBroadcast 我安装了一个名为cordova插件installreferer的cordova插件和一个npm模块installreferer。当我尝试在开发模式下构建应用程序时,得到的响应是空数组。但是当我在生产模式下构建它时,我得到了plugin\u not\u found错误。(注:我已将其添加到app.module.ts中的提供商中) 我还意识到,InstallBroadca

在过去的一周里,我一直在琢磨如何在一款爱奥尼亚应用程序中使用它。我尝试过使用以下方法:

方法1:InstallBroadcast

我安装了一个名为
cordova插件installreferer
的cordova插件和一个npm模块
installreferer
。当我尝试在开发模式下构建应用程序时,得到的响应是空数组。但是当我在生产模式下构建它时,我得到了
plugin\u not\u found
错误。(注:我已将其添加到app.module.ts中的提供商中)

我还意识到,InstallBroadcast现在已被弃用。我们必须切换到播放安装引用API

方法2:播放安装推荐人API

我尝试安装一个名为
cordova安装参考api
的cordova插件。并尝试了以下代码:

declare var referrer: any;
...
initializeApp() {
  try{
    referrer.get().then((referrer) => {
      alert(JSON.stringify(referrer));
    });
  }catch(err){
    alert(err);
  }
...
获取以下错误:
ReferenceError:未定义referer


请帮助我正确获取referer,如果我做错了,请告诉我。

在您的方法2中:您声明了一个变量
referer
,但我在代码中看不到初始化,并且您得到的错误也没有定义。所以,我认为你还没有定义它

删除声明的变量并用以下内容替换代码:

cordova.plugins.referrer.get().then((referrer) => {
    console.log(referrer);
    // Remove these comments, just an example from the original API
    // Result:
    // {
    //     clickTimestamp: 0,
    //     installBeginTimestamp: 0,
    //     referrer: "utm_source=google-play&utm_medium=organic"
    // } 

}).catch((error) => {
}); 

并检查它是否有效。代码引用自。

我以为我们在ionic中使用cordova插件有不同的方法,结果证明这只是当前使用cordova插件的方法。注意:不要忘记添加
声明let cordova:any
上述来自官方文档的代码工作得非常好。@CraziestHacker很高兴,这很有帮助。
cordova.plugins.referrer.get().then((referrer) => {
    console.log(referrer);
    // Remove these comments, just an example from the original API
    // Result:
    // {
    //     clickTimestamp: 0,
    //     installBeginTimestamp: 0,
    //     referrer: "utm_source=google-play&utm_medium=organic"
    // } 

}).catch((error) => {
});