Phonegap IOS - Plugin Push Setup

前端 未结 2 2014
走了就别回头了
走了就别回头了 2020-12-22 05:44

I\'m developing an App using Phonegap and Phonegap Build. The app has been pretty much completed but I\'m not working on the Push Notifications.

I\'m struggling to g

2条回答
  •  借酒劲吻你
    2020-12-22 06:14

    So there was 2 sections to this, First what jesseMonroy mentioned, my code wasn't being picked up properly and my js file wasn't being run properly.

    The second part was that I wasn't calling a register function, which allows you to get a device_token.

            push.registerDevice({ alert: true, badge: true, sound: true }, function (status) {
                app.myLog.value += JSON.stringify(['registerDevice status: ', status]) + "\n";
                app.storeToken(status.deviceToken);
                alert(status.deviceToken)
            });
    

    This is what i was missing. my whole init section looks like this;

    var push = PushNotification.init({
                "android": {
                    "senderID": "1234567890"
                },
                "ios": { "alert": "true", "badge": "true", "sound": "true" },
                "windows": {}
            });
    
            push.on('registration', function (data) {
                console.log("registration event");
                //document.getElementById("regId").innerHTML = data.registrationId;
                alert(data.registrationId)
                console.log(JSON.stringify(data));
            });
    
            push.on('notification', function (data) {
                console.log("notification event");
                console.log(JSON.stringify(data));
                var cards = document.getElementById("cards");
                var card = '
    ' + '
    ' + '
    ' + '
    ' + ' ' + data.title + '' + '

    ' + data.message + '

    ' + '
    ' + '
    ' + '
    ' + '
    '; cards.innerHTML += card; push.finish(function () { console.log('finish successfully called'); }); }); push.on('error', function (e) { console.log("push error"); }); // var pushNotification = window.plugins.PushNotification; push.registerDevice({ alert: true, badge: true, sound: true }, function (status) { app.myLog.value += JSON.stringify(['registerDevice status: ', status]) + "\n"; app.storeToken(status.deviceToken); alert(status.deviceToken) });

提交回复
热议问题