gpt4 book ai didi

cordova - phonegap 推送插件 - 如何将源 ="pgb"更改为 npm

转载 作者:行者123 更新时间:2023-12-02 01:21:05 25 4
gpt4 key购买 nike

我构建了一个带有推送消息的应用程序我收到消息插件不再可用。

“此应用使用来自 PhoneGap Build 存储库的插件。这些插件将在 2016 年 11 月 15 日之后无法访问”

推送插件的config.xml:

这是我的代码:

                    try {
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android' || device.platform == 'amazon-fireos') {
pushNotification.register(pushsuccessHandler, pusherrorHandler, {
"senderID": "123456789",
"ecb": "onNotification"
});
} else {
pushNotification.register(tokenHandler, pusherrorHandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN" });
}
}
catch (err) {
txt = "There was an error on this page.\n\n";
txt += "Error: " + err.message + "\n\n";
console.log(txt);
}

//处理 Android 的 GCM 通知 函数 onNotification(e) { 切换(e.event){

            case 'registered':
alert(e.regid);
if (e.regid.length > 0) {
alert(e.regid);
var jsonText = {
userName: empId.value,
RegId: e.regid,
IsAndroid: 1,
}
$.ajax({
type: "Post",
url: basePath + "ExternalWebService.asmx/SaveRegId",
data: JSON.stringify(jsonText),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("secccess saveRegId");
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.responseText + " " + xhr.error);
alert("error saveRegId");
}
});

}
break;
case 'message':

var snd = new Media("./audio/sound.mp3");
snd.play();
if (e.foreground) {//when the application is in the foreground (we can see it)
window.location.reload();
}
else { // otherwise we were launched because the user touched a notification in the notification tray.
if (e.coldstart) {//when the application is closed
window.location.reload();
}
else {//when the application is open but in the background (we can’t see it)
window.location.reload();
}
}
break;
case 'error':
console.log('ERROR -> MSG:' + e.msg + '');
break;
default:
console.log('Unknown, an event was received and we do not know what it is');
break;
}

}
// handle callback notifications
function pushsuccessHandler(result) {
alert('pushNotification register success:' + result + '');
}

function pusherrorHandler(error) {
alert('pushNotification register error:' + error + '');
}
function tokenHandler(result) {
console.log('token: ' + result + '');
var jsonText = {
userName: empId.value,
RegId: result,
IsAndroid: 0,
}
$.ajax({
type: "Post",
url: basePath + "ExternalWebService.asmx/SaveRegId",
data: JSON.stringify(jsonText),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
console.log("secccess saveRegId");
},
});
}

最佳答案

你有这个 < gap:plugin name="com.phonegap.plugins.pushplugin" spec="2.5.0" source="pgb" />

你必须以这样的方式结束:

<plugin name="phonegap-plugin-push" source="npm" />

你怎么做到的?

首先转到https://www.npmjs.com/并搜索插件的 ID,在本例中为 com.phonegap.plugins.pushplugin .如果找到了,继续使用相同的id

在这种情况下,该插件不在 npmjs 上,因为它已被弃用,因此请转到 google 并搜索 com.phonegap.plugins.pushplugin

第一个链接指向 old deprecated repo .该插件的 README.md 将指向 new version of the plugin在插件的安装信息中有一个 additional resources section这解释了如何在 phonegap build 上使用插件

<preference name="android-build-tool" value="gradle" />
<plugin name="phonegap-plugin-push" source="npm">
<param name="SENDER_ID" value="<Your Sender ID>" />
</plugin>

如果你想指定一个版本,你可以像以前一样使用 spec 属性来完成,这是你在说话时使用最新版本必须添加的内容

<preference name="android-build-tool" value="gradle" />
<plugin name="phonegap-plugin-push" spec="1.8.3" source="npm">
<param name="SENDER_ID" value="<Your Sender ID>" />
</plugin>

如果你想继续使用你当前的插件,尽管它已被弃用,你可以使用 github url 而不是使用 npm

<plugin spec="https://github.com/phonegap-build/PushPlugin" />

关于cordova - phonegap 推送插件 - 如何将源 ="pgb"更改为 npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40242537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com