我使用推送消息构建了一个应用程序 我得到了消息插件不再可用。
"此应用程序使用PhoneGap Build存储库中的插件。这些插件在2016年11月15日之后无法访问"
pushplugin的配置文件:
< gap:plugin name =" com.phonegap.plugins.pushplugin"规格=" 2.5.0"源=" PGB" />
这是我的代码:
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通知 function onNotification(e){ switch(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");
},
});
}
答案 0 :(得分:2)
你有这个
< 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网址而不是使用npm
<plugin spec="https://github.com/phonegap-build/PushPlugin" />
答案 1 :(得分:0)
好的插件存在于NPM存储库中,但您只需搜索它们即可。它们具有不同的ID(包ID)。以下是Cordova插件搜索页面:http://cordova.apache.org/plugins/
我不确定你使用的是哪一个,但这里有一些:
https://www.npmjs.com/package/cordova-plugin-pushplugin
https://www.npmjs.com/package/PushPlugin_V2
https://www.npmjs.com/package/cordova-plugin-gcmpushplugin
以下是来自Phonegap的博客文章,称PGP存储库将于11月中旬关闭:
http://phonegap.com/blog/2016/10/13/pgb-repository-shutting-down/