简体   繁体   English

Phonegap插件推送注册设备,但未收到通知

[英]Phonegap plugin push registers device but doesn't receive notifications

So i've been struggling making push plugin ( https://github.com/phonegap/phonegap-plugin-push ) work on iOS for a while (I don't know anything about iOS development). 所以我一直在努力使推送插件( https://github.com/phonegap/phonegap-plugin-push )在iOS上工作一段时间(我对iOS开发一无所知)。 It seems to register the device correctly, but when i send notifications via pushwatch it sends it without problems to Apple but i don't receive anything (working like a charm for Android). 它似乎正确注册了设备,但是当我通过按钮式手表发送通知时,它可以毫无问题地将其发送给Apple,但我什么也没收到(就像Android的魅力一样)。

The fact that it works on Android and i can send the notification to Apple makes me think the problem is with certificates. 它可以在Android上运行并且可以将通知发送给Apple,这一事实使我认为问题出在证书上。 I've generated the app ID and enabled push notifications, created push certificates for both production and development (neither of them working) and a provisioning profile for development. 我已经生成了应用程序ID并启用了推送通知,创建了用于生产和开发的推送证书(它们都不起作用)以及用于开发的配置文件。

On Xcode i've downloaded the provisioning profile from preferences/agent/download all (This is where i think i'm messing this up) and i can build the app without any problem using automatic build settings. 在Xcode上,我已经从偏好设置/代理/全部下载了配置文件(这是我认为要搞砸的地方),并且我可以使用自动构建设置来构建应用程序而没有任何问题。 When i run the app on my iPhone i get a device token, so i know it registers the device. 当我在iPhone上运行该应用程序时,我得到了一个设备令牌,因此我知道它注册了该设备。

Here is my index.js (I'm using the push plugin template app) 这是我的index.js(我正在使用推插件模板应用程序)

var app = {
// Application Constructor
initialize: function() {
    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() {
    console.log('Received Device Ready Event');
    console.log('calling setup push');

    if(device.platform == "Android"){ //Android
        console.log('Android');
        var pushNotification = window.plugins.pushNotification;
        pushNotification.register(app.successHandler, app.errorHandler, {"senderID":"XXX","ecb":"app.onNotification"});
    }
    else if(device.platform == "iOS"){ //iOS
        console.log('iOS');
        var pushNotification = PushNotification.init({
            "android": {
                "senderID": "XXX"
            },
            "ios": {
              "badge":"true",
              "sound":"true",
              "alert":"true",
              "ecb":"onNotification"
            },
            "windows": {} 
        });
    }

},
// result contains any message sent from the plugin call
successHandler: function(result) {
    console.info('Callback Success! Result = '+result)
},
errorHandler:function(error) {
    console.info(error);
},
onNotification:function(e) {
    push.on('registration', function(data) {
        console.log('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
        }
    });

    push.on('error', function(e) {
        console.log("push error = " + e.message);
    });

    push.on('notification', function(data) {
        console.log('notification event');
        navigator.notification.alert(
            data.message,         // message
            null,                 // callback
            data.title,           // title
            'Ok'                  // buttonName
        );
   });
}};

It seems like i can send the notification but apns doesn't know where to send it or like it is sent but my device can't receive it because isn't linked to the certificate. 似乎我可以发送通知,但apns不知道将通知发送到哪里或发送给谁,但我的设备无法接收,因为未链接到证书。

Thank you in advance. 先感谢您。

Edit: Following the steps in this tutorial seems to have solved my problem. 编辑:按照本教程中的步骤进行操作似乎已经解决了我的问题。 https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/ The problem i think was the phrase the key asks you to write. https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/我认为的问题是密钥要求您编写的短语。 Once i've removed it the notifications have started to appear. 一旦删除它,通知就会开始出现。

Following the steps in this tutorial seems to have solved my problem. 遵循本教程中的步骤似乎已经解决了我的问题。 https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/ The problem i think was the phrase the key asks you to write. https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/我认为的问题是密钥要求您编写的短语。 Once i've removed it the notifications have started to appear. 一旦删除它,通知就会开始出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM