我使用了(https://github.com/phonegap-build/PushPlugin/tree/master/Example/www)的示例源代码.问题是,当我安装我的应用程序并启动它我的Android手机(或Android SDK模拟器)时,它无法将设备注册到Android GCM.弹出所有时间错误 - "设备未定义".我不确切知道如何捕获错误,为什么它无法注册设备.
我执行的步骤是:
- 创建了Phonegap项目
- 安装在3个插件之后(cordova-plugin-device.git,cordova-plugin-media.git,PushPlugin).
这是我的Index.html代码:
<html>
<head>
<title>com.PhoneGap.c2dm</title>
</head>
<body>
<!--<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>-->
<link rel="stylesheet" href="ext/jquery/jquery.mobile-min.css">
<script type="text/javascript" src="ext/jquery/jquery-min.js"></script>
<script type="text/javascript" src="ext/jquery/jquery.mobile-min.js"></script>
<script type="text/javascript" src="ext/jquery.qrcode.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" src="PushNotification.js"></script>
<script type="text/javascript">
var pushNotification;
function onDeviceReady() {
$("#app-status-ul").append('<li>deviceready event received</li>');
document.addEventListener("backbutton", function(e)
{
$("#app-status-ul").append('<li>backbutton event received</li>');
if( $("#home").length > 0)
{ …Run Code Online (Sandbox Code Playgroud) 我尝试使用pushNotification注册我的设备,使用演示.它不起作用.打印"Cordova PushNotification插件演示"和"注册android"并查看警报"OK"(successHandler函数有效).问题是"ecb"不起作用.为什么?你能帮助我吗?
我与Cordova一起安装的插件有:PushPlugin,Device,Notification,InAppBrowser和Network Information.
我在我的LG L9和模拟器上试过这个应用程序.同样的问题.
这是代码:
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script>
<script type="text/javascript" src="PushNotification.js"></script>
<script type="text/javascript">
var pushNotification;
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
function onDeviceReady() {
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
$("#app-status-ul").append("<li>registering android</li>");
window.plugins.pushNotification.register(successHandler, errorHandler, {
"senderID": "my_id",
"ecb": "onNotificationGCM"
}); // required!
} else {
$("#app-status-ul").append("<li>registering iOS</li>");
pushNotification.register(tokenHandler, errorHandler, {
"badge": "true",
"sound": "true",
"alert": "true",
"ecb": "onNotificationAPN"
}); // required!
}
}
// handle …Run Code Online (Sandbox Code Playgroud) 我刚刚使用PhoneGap CLI 安装了PhoneGap 3.5和PushPlugin.我使用PhoneGap CLI创建了一个项目.在receivedEventindex.js 的方法中,我添加了以下行:
var pushNotification = window.plugins.pushNotification;
pushNotification.register(myTokenMethod, onError, {"badge": "true", "sound": "true", "alert":"true", "ecb": "mycallback"}
Run Code Online (Sandbox Code Playgroud)
这会导致xCode中的错误:
CDVPlugin class PushPlugin (pluginName: PushPlugin) does not exist
ERROR: Plugin 'PushPlugin' not found or is not a CDVPlugin. Check your plugin mapping in config.xml
Run Code Online (Sandbox Code Playgroud)
虽然说明并没有表明我需要自动安装插件,但我继续补充说
<feature name="PushPlugin">
<param name="ios-package" value="PushPlugin" />
</feature>
Run Code Online (Sandbox Code Playgroud)
到我的config.xml并收到相同的错误.插件版本是2.4,我使用iPhone 6作为测试设备和xCode 6.
任何想法在哪里看?
plugins apple-push-notifications ios cordova phonegap-pushplugin
我正在我的cordova应用程序中实施Google Cloud Messaging服务.到目前为止一切运作良好.然而,我有一些问题困扰我希望有人可以为我澄清它们.1)在代码的这一部分,我获取设备GCM regID并进一步将其保存到我的服务器上.我想知道是否应该调用此脚本,从而在用户打开应用程序时将GCM regID保存到我的服务器,或者应该调用并保存一次.
function onNotification(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("regID = " + e.regid);
}
break;
}
}
Run Code Online (Sandbox Code Playgroud)
2)我在控制台上注意到我的注册ID有时会发生变化.我想知道为什么会发生这种情况,是否正常以及我是否应该在我的服务器上更新用户GCM regID.
如果有人能为我澄清这些,我会很高兴的.谢谢
android push-notification cordova google-cloud-messaging phonegap-pushplugin
我只缺了一步,我能感觉到......
我将phonegap插件添加到我的项目中:
cordova plugin add phonegap-plugin-push --save --variable SENDER_ID="-redacted-"
Run Code Online (Sandbox Code Playgroud)
确实它将条目保存到我的config.xml文件中.当我构建并运行浏览器版本时
cordova build myApp browser
cordova run myApp browser
Run Code Online (Sandbox Code Playgroud)
我收到错误消息: Error: exec proxy not found for :: PushNotification :: init
在浏览器项目文件夹中,下面myapp\platforms\browser\platform_www\plugins有一个phonegap-plugin-push\www包含单个push.js文件的文件夹,仅此而已. push.js调用本机插件(例如:) exec(success, fail, 'PushNotification', 'init', [options]);,但实际运行代码的插件文件是......好吧,我不知道.这可能是问题,你不觉得吗?:)
任何有助于在Chrome中运行的帮助都将是一个很大的帮助.在此之后我将继续测试Android.
phonegap-plugins cordova cordova-plugins phonegap-pushplugin
我正在使用phonegap-plugin-push来接收Cordova 应用程序中的通知。我正在 android Marsh-mellow 上部署进行测试。
我想在应用程序处于后台时查看并存储通过Firebase 控制台收到的通知内容。
这是我的代码 -
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady(){
var push = PushNotification.init({ "android": {"senderID": "91254247XXXX"}});
push.on('registration', function(data) {
console.log(data.registrationId);
//document.getElementById("gcm_id").innerHTML = data.registrationId;
});
push.on('notification', function(data) {
alert("On Notification function!!");
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
console.log("notification event");
console.log(JSON.stringify(data));
alert(JSON.stringify(data));
//Do something
});
push.on('error', function(e) {
alert(e);
});
}
Run Code Online (Sandbox Code Playgroud)
当应用程序位于前台(在屏幕上)时,我可以正确接收内容(标题、消息、数据等),并且可以直接在应用程序中的警报框中看到它们。
但是当应用程序在后台(不是在屏幕上而是在后台运行)时,我会在通知区域收到通知。当我点击收到的通知时,它会将我重定向到应用程序中最后打开的页面。
该函数push.on('notification', function(data) {}未被调用。不显示任何警报消息。有人可以帮助我如何访问通知消息和数据吗?
android push-notification cordova firebase phonegap-pushplugin
我在Ionic2中使用以下插件进行推送通知
http://ionicframework.com/docs/native/push/
预期行为: 当应用程序关闭时,收到通知,当用户点击通知时,应用程序打开后应打开("通知")事件.
实际行为: 我成功收到通知.但是当应用程序处于后台或关闭时,当我收到通知并点击通知时,on("notification")事件未触发.
Cordova版本 7.0.1 Android版本 6.2.3
我的代码:
this.platform.ready().then(() => {
this.pushsetup();
});
private pushOptions: PushOptions;
private pushObject: PushObject;
pushsetup() {
// to check if we have permission
this.push.hasPermission()
.then((res: any) => {
if (res.isEnabled) {
console.log('We have permission to send push notifications');
// configuration of push notification
this.pushOptions = {
android: {
senderID: 'XXXXXXXXXXX',
icon: 'icon_notification'
},
ios: {
alert: 'true',
badge: true,
sound: 'false',
senderID: 'XXXXXXXXXXX'
},
windows: {}
};
this.pushObject = this.push.init(this.pushOptions);
// attach …Run Code Online (Sandbox Code Playgroud) push-notification cordova cordova-plugins phonegap-pushplugin ionic2
我陷入了这个phonegap项目.在Android和iOS <= 7上,一切都很完美,但在iOS> = 8.0时失败.将出现一个弹出窗口,其中显示消息:"找不到变量:device"

这是我得到的消息:
这是我的HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
<script type="text/javascript" src="cordova.js" charset="utf-8"></script>
<script type="text/javascript" src="js/PushNotification.js" charset="utf-8"></script>
</head>
<body onload="documentReady();">
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
这是我在标签底部加载的'index.js'.
var myPushNotification;
// result …Run Code Online (Sandbox Code Playgroud)phonegap-plugins cordova phonegap-build phonegap-pushplugin ios8
显然,在(OR ||)运算符出现问题之后,当我使用(AND &&)运算符时收到了通知,而当我使用(OR ||)时却没有收到通知。
那么,有没有其他方法可以将通知发送给那些没有(OR ||)运算符的用户(TopicA或TopicB或TopicC)?