[英]Can't receive push notification from Parse server and ionic app (ios)
I step into a problem that I don't even know what is the problem. 我遇到一个问题,我什至不知道是什么问题。
Trying with ios first. 首先尝试使用ios。
I am making the push notification from parse server open source. 我正在从解析服务器开源发出推送通知。 I set up the parse server for push:
我设置了解析服务器进行推送:
"push": {
"ios":{
"pfx": "/var/www..../Certificates.p12",
"passphrase": "...",
"bundleId": "com.xxxx.testPushNotification",
"production": false
}
}
I am using this plugin https://github.com/phonegap-build/PushPlugin . 我正在使用这个插件https://github.com/phonegap-build/PushPlugin 。 Here is my platform
这是我的平台
Installed platforms:
ios 4.3.1
Available platforms:
amazon-fireos ~3.6.3 (deprecated)
android ~6.0.0
blackberry10 ~3.8.0
browser ~4.1.0
firefoxos ~3.6.3
osx ~4.0.1
webos ~3.7.0
and 和
cordova 6.4.0
and here is the code in app.js 这是app.js中的代码
$("#app-status-ul").append('<li>registering ' + device.platform + '</li>');
pushNotification.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
// result contains any message sent from the plugin call
function successHandler (result) {
alert('result = ' + result);
}
// result contains any error description text returned from the plugin call
function errorHandler (error) {
alert('error = ' + error);
}
function onNotificationAPN (event) {
if ( event.alert )
{
navigator.notification.alert(event.alert);
}
if ( event.sound )
{
var snd = new Media(event.sound);
snd.play();
}
if ( event.badge )
{
pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
}
}
function tokenHandler (result) {
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
alert('device token = ' + result);
}
// fired when push notification is received
window.onNotification = function (e) {
navigator.notification.alert('Notification received: ' + JSON.stringify(e));
}
var pushNotification = window.plugins.pushNotification;
pushNotification.register(successHandler, errorHandler, {"channelName":"xxxx","ecb":"onNotification"});
function successHandler(result) {
console.log('registered###' + result.uri);
// send uri to your notification server
}
function errorHandler(error) {
console.log('error###' + error);
}
basically I may manage the server side since I sent several of messages but they are not actually sent. 基本上,我可以管理服务器端,因为我发送了几条消息,但实际上并没有发送。
please click to see picture 请点击查看图片
I managed to get the .p12 and .pem and the app id is matched between app and server side. 我设法得到了.p12和.pem,并且应用程序ID在应用程序和服务器端之间匹配。
Where is my problem? 我的问题在哪里? Help would be appreciated.
帮助将不胜感激。
I found my answer myself, hope it helps 我自己找到了答案,希望对您有所帮助
inside deviceReady() 内部deviceReady()
if(window.ParsePushPlugin){
ParsePushPlugin.getInstallationId(function(id) {
// note that the javascript client has its own installation id,
// which is different from the device installation id.
alert("device installationId: " + id);
}, function(e) {
alert('error');
});
ParsePushPlugin.getSubscriptions(function(subscriptions) {
alert(subscriptions);
}, function(e) {
alert('error');
});
ParsePushPlugin.subscribe('SampleChannel', function(msg) {
alert('OK');
}, function(e) {
alert('error');
});
ParsePushPlugin.unsubscribe('SampleChannel', function(msg) {
alert('OK');
}, function(e) {
alert('error');
});
ParsePushPlugin.on('receivePN', function(pn){
alert('yo i got this push notification:' + JSON.stringify(pn));
});
//inside config.xml //在config.xml内部
<preference name="ParseAppId" value="xxxxxx" />
<preference name="ParseServerUrl" value="http://xxxxx:1389/parse" />
<preference name="ParseGcmSenderId" value="xxxxxx" />
<preference name="ParseMultiNotifications" value="true" />
Plugin : https://github.com/taivo/parse-push-plugin 插件: https : //github.com/taivo/parse-push-plugin
Notice: set appId (app bundle) the same between server and app and make sure p12 and pem file in the root folder of your app. 注意:在服务器和应用程序之间设置appId(应用程序捆绑包)相同,并确保应用程序的根文件夹中有p12和pem文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.