我正在开发适用于iOS的Phonegap应用程序,并希望启用推送通知。我使用GCM,当我发送通知时谷歌会让我成功,但IOS设备没有显示任何内容。
有我的代码:
"android": {
"senderID": "xxxxxxxx", "icon": "icon", "badge": "true", "iconColor": "white", "sound": "true", "soundname": "nb"
},
"ios": {
"senderID": "xxxxxxxx",
"alert": "true",
"badge": "true",
"sound": "true",
"usesGCM":true,
"sandbox":false,
},
"windows": {}
答案 0 :(得分:0)
首先安装推送通知插件。
phonegap plugin add phonegap-plugin-push
编写java脚本代码后,如下iOS推送
var note = new apn.Notification();
note.badge = 1;
note.sound = "beep.wav"; //path to your sound
note.contentAvailable = 1;
note.alert = { "body" : msg, "action-loc-key" : "Show Me!" , "launch-image" : "mysplash.png"};
//note.payload = {'uuid': data.uuid}; // additional payload
note.device = data.deviceId;
var callback = function(errorNum, notification){
console.log('Error is: %s', errorNum);
//console.log("Note " + JSON.stringify(notification));
}
var options = {
gateway: 'gateway.sandbox.push.apple.com',
errorCallback: callback,
cert: 'test.pem',
key: 'test.pem', // ** NEED TO SET TO YOURS
passphrase: '', // ** NEED TO SET TO YOURS
//port: 2195,
enhanced: true,
cacheLength: 100
}
var apnProvider = new apn.Provider(options);
apnProvider.send(note, myDevice).then( (result) => {
console.log("Result :: ",JSON.stringify(result));
});
它会起作用。