如何在电容器应用中设置Cordova插件变量?

问题描述

我正在尝试使用https://docs.wonderpush.com/docs/mobile-push-notifications-ionic上的文档为Ionic建立Wonderpush集成

说明要求使用以下命令安装插件

ionic cordova plugin add wonderpush-cordova-sdk --variable CLIENT_ID=YOUR_CLIENT_ID --variable CLIENT_SECRET=YOUR_CLIENT_SECRET --variable SENDER_ID=YOUR_SENDER

...但是由于我的应用程序是Capacitor应用程序,因此必须使用以下命令安装插件:

npm install wonderpush-cordova-sdk

以这种方式安装插件时,我不知道如何设置CLIENT_ID,CLIENT_SECRET和SENDER_ID(此命令没有“ --variable”标志),并且出现运行时错误在我的设备上运行该应用时说这些变量丢失。您知道如何填充这些值吗?预先感谢!

解决方法

电容器应用程序在安装插件时不支持变量。这是因为电容器应用程序是面向本机的,并且不像Cordova那样通过命令行提供配置挂钩。

要使用插件添加变量,您需要手动更新Android的AndroidManifest.xml和iOS的Info.plist 。您可以在https://www.joshmorony.com/using-cordova-plugins-that-require-install-variables-with-capacitor/

上获得有关它的更多详细信息

示例:<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

尽管Ionic插件的当前文档中缺少这些配置设置,但对于流行的插件,您可以检查其本机版本文档并相应地更新平台文件。

Wondershare Android配置:寻找“指定配置选项的替代方法”部分

https://docs.wonderpush.com/docs/android-sdk#alternate-ways-of-specifying-configuration-options

,

我能够找到将这些变量放在哪里。在// Get the modal var modal = document.getElementById("myModal"); // Get the button that opens the modal var btn = document.getElementById("myBtn"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks the button,open the modal btn.onclick = function() { modal.style.display = "block"; } // When the user clicks on <span> (x),close the modal span.onclick = function() { modal.style.display = "none"; } // When the user clicks anywhere outside of the modal,close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } // Get the modal var modal2 = document.getElementById("myModal2"); // Get the button that opens the modal var btn = document.getElementById("myBtn2"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close2")[0]; // When the user clicks the button,open the modal btn.onclick = function() { modal2.style.display = "block"; } // When the user clicks on <span> (x),close the modal span.onclick = function() { modal2.style.display = "none"; } // When the user clicks anywhere outside of the modal,close it window.onclick = function(event) { if (event.target == modal) { modal2.style.display = "none"; } } 中,我对capacitor.config.json元素进行了以下更改。

"cordova": {}

然后,我运行"cordova": { "preferences": { "WONDERPUSH_CLIENT_ID": "<YOUR-CLIENT-ID>","WONDERPUSH_CLIENT_SECRET": "<YOUR-CLIENT-SECRET>","WONDERPUSH_LOGGING": true,"WONDERPUSH_AUTO_INIT": true,"WONDERPUSH_REQUIRES_USER_CONSENT": false } } ,从IDE中启动应用程序,并成功!

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...