我在我的科爾多瓦應用程序中使用推送通知plugin。我能夠使用GCM獲取Android通知,而且非常簡單。現在,iOS自從星期天以來,對我來說是一件非常痛苦的事,差不多4天了。我將分享我迄今爲止所做的事情。請幫助我也獲取iOS設備上的通知。需要在科爾多瓦應用中使用本機APNs/GCM爲iOS推送通知的指導
據插件,在應用程序端我Java腳本看起來像這樣
myApp.controller('Register', function ($scope) {
$scope.regGCM = function() {
document.addEventListener('deviceready', onDeviceReady, false);
}
function onDeviceReady() {
var push = PushNotification.init({
"android": {
"senderID": "41502493944",
"sound": "true",
"vibrate": "true",
},
"ios": {
"alert": "true",
"badge": "true",
"sound": "true",
},
"windows": {}
});
push.on('registration', function (data) {
var deviceid = data.registrationId;
alert(deviceid);
});
push.on('notification', function (data) {
console.log("notification");
});
push.on('error', function (e) {
console.log("push error");
});
}
});
當regGCM()
觸發iOS設備要求的權限,允許推送通知我的應用程序,它returns a token
。
然後在網上測試推送通知我使用這site這需要我們的token
和.pem
文件。
要創建一個.pem
文件,我做了以下事情。
1)從here創建p.notification證書。
2)安裝在mac keychain中。
3)導出安裝證書爲pushcert.p12
文件。
4)在終端執行這個命令(openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts
)我得到了pushcert.pem
文件。
在線測試site說消息已發送,但我從來沒有收到通知到我的iOS設備。我是新來推通知,不知道正確的步驟,可能會錯過一些東西。有沒有人知道如何在cordova中使用iOS p.notification。我不介意使用GCM或本地APN的方式。
任何幫助將不勝感激。
謝謝你的迴應=)我是新來的iOS和不知道我是否遵循了正確的步驟。我拿到了設備令牌。你怎麼看 ?可能是我的證書問題? –