我试图在APN中注册iOS设备(iPhone 6s)以发送推送通知。我使用PhoneGap进行开发,使用Adobe PhoneGap编译代码并获取.ipa。我正在使用phonegap-plugin-push。
当我使用init函数时,我从未收到注册事件,只需使用此插件的示例模板代码。
我认为Apple证书已正确配置:开发,推送服务和配置证书以及启用推送通知的App ID。
所以...我不知道出了什么问题,但我无法获取设备令牌或只是看到提示在应用中要求允许推送通知。
以下是我使用的代码(来自模板phonegap-template-push):
var app = {
// Application Constructor
initialize: function() {
window.alert('calling bindEvents');
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
window.alert('Received Device Ready Event');
window.alert('calling setup push');
try{
app.setupPush();
}
catch(err){
window.alert(err.message);
}
window.alert('Ready');
},
setupPush: function() {
window.alert('calling push init');
var push = PushNotification.init({
"android": {
"senderID": "12345679"
},
"ios": {
"sound": true,
"vibration": true,
"badge": true
},
"windows": {}
});
window.alert('after init');
push.on('registration', function(data) {
window.alert('registration event: ' + data.registrationId);
var oldRegId = localStorage.getItem('registrationId');
if (oldRegId !== data.registrationId) {
// Save new registration ID
localStorage.setItem('registrationId', data.registrationId);
// Post registrationId to your app server as the value has changed
}
var parentElement = document.getElementById('registration');
var listeningElement = parentElement.querySelector('.waiting');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
});
push.on('error', function(e) {
window.alert("push error = " + e.message);
});
push.on('notification', function(data) {
window.alert('notification event');
navigator.notification.alert(
data.message, // message
null, // callback
data.title, // title
'Ok' // buttonName
);
});
}
};