phonegap 推送插件 - 如何将 source="pgb" 更改为 npm
phonegap push plugin- How do I change source="pgb" to npm
我构建了一个带有推送消息的应用程序
我收到消息插件不再可用。
"This app uses plugins from the PhoneGap Build repository. These plugins won't be accessible after Nov 15th, 2016"
config.xml 推送插件:
< gap:plugin name="com.phonegap.plugins.pushplugin" spec="2.5.0" source="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 通知
函数 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");
},
});
}
好的,这些插件存在于 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 的博客 post,称 PGP 存储库将于 11 月中旬关闭:
http://phonegap.com/blog/2016/10/13/pgb-repository-shutting-down/
你有这个
< 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
首先link指向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" />
我构建了一个带有推送消息的应用程序 我收到消息插件不再可用。
"This app uses plugins from the PhoneGap Build repository. These plugins won't be accessible after Nov 15th, 2016"
config.xml 推送插件:
< gap:plugin name="com.phonegap.plugins.pushplugin" spec="2.5.0" source="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 通知 函数 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");
},
});
}
好的,这些插件存在于 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 的博客 post,称 PGP 存储库将于 11 月中旬关闭:
http://phonegap.com/blog/2016/10/13/pgb-repository-shutting-down/
你有这个
< 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
首先link指向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" />