Performing Phonegap Push Notifications

I know this question was asked before, but my problem is that there are so many different answers, and let's just say that the documents are not so good, the fact is that I want to implement push notifications on my app, but I am stuck in steps 3 and 4 of this image.

I followed this tutorial, but when I want to send a private token to my server , what do I need to distinguish ios from android? . If you look at this tutorial, you will see that there are actually two methods to distinguish between APNS and GCM (and this is an old tutorial!), But if you go to the docs phone call or this manual that I followed, the methods are not .

Does anyone know an updated tutorial that I can follow?

+4
source share
2 answers

To implement a push notification, you can follow this link (which you already followed, and this is for the updated plugin, another tutorial that you mentioned explained the old deprecated plugin).

ios android, . , (iOS Android), - :

push.on('registration', function(data) {
    var deviceToken =  data.registrationId
});

, :

  • .

    ( . ). :

    var devicePlatform = device.platform;
    
  • :

    function getDevicePlatform() {
        var userAgent = navigator.userAgent || navigator.vendor || window.opera;
        if (/windows phone/i.test(userAgent)) {
            return "Windows";
        }
        if (/android/i.test(userAgent)) {
           return "Android";
        }
        if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
           return "iOS";
       }
       return "unknown";
    }
    

, .

, , .

, .

+2

PHONEGAP PUSH ( 1.3.0)

.

  • , Android SDK Manager:

    • Android 23 Maven ( Android) 20
    • Google Play 27
    • Google 22
  • CLI

    cordova add phonegap-plugin-push -variable SENDER_ID = "XXXXXXX"

    XXXXXXX SENDER_ID = "XXXXXXX" Google. Google, , .

  • javascript

    var push = PushNotification.init({
        android: {
            senderID: "XXXXXXX"
        },
        browser: {
            pushServiceURL: 'http://push.api.phonegap.com/v1/push'
        },
        ios: {
            alert: "true",
            badge: "true",
            sound: "true"
        },
        windows: {}
    });
    
    push.on('registration', function(data) {
        console.log("data.registrationId :"+data.registrationId);
    });
    
    push.on('notification', function(data) {
        // data.message,
        // data.title,
        // data.count,
        // data.sound,
        // data.image,
        // data.additionalData
    });
    
    push.on('error', function(e) {
        // e.message
        //alert("e.message:"+ e.message)
    });
    

1. Cordova CLI (3.6.3 or newer)
2. Android (cordova-android 4.0.0 or higher)
3. Browser
4. iOS (cordova-ios 4.1.0 or higher)
5. Windows Universal (not Windows Phone 8)

...

+2

Source: https://habr.com/ru/post/1649766/


All Articles