Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
109 stars 139 forks source link

Pushwoosh not allowed push flag #246

Closed int3rnet closed 6 years ago

int3rnet commented 7 years ago

Dear in pushwoosh

good times guys , i have a code for init pushwoosh in Cordova but i need to fire a trigger once the user not allowed the push plugin

this is my code 👍

`

function onPushwooshInitialized(pushNotification) {

//if you need push token at a later time you can always get it from Pushwoosh plugin
pushNotification.getPushToken(
    function(token) {
        console.info('push token: ' + token);
                    localStorage.setItem("DeviceToken",token); 
    }
);

//and HWID if you want to communicate with Pushwoosh API
pushNotification.getPushwooshHWID(
    function(token) {
        console.info('Pushwoosh HWID: ' + token);
    }
);

//settings tags
pushNotification.setTags({
        tagName: "user_type",
        intTagName: 1
    },
    function(status) {
        console.info('setTags success: ' + JSON.stringify(status));
    },
    function(status) {
        console.warn('setTags failed');
    }
);

pushNotification.getTags(
    function(status) {
        console.info('getTags success: ' + JSON.stringify(status));
    },
    function(status) {
        console.warn('getTags failed');
    }
);

//start geo tracking.
pushNotification.startLocationTracking();

}

function initPushwoosh() { var pushNotification = cordova.require("pushwoosh-cordova-plugin.PushNotification");

//set push notifications handler
document.addEventListener('push-notification',
    function(event) {
        var message = event.notification.message;
        var userData = event.notification.userdata;

        document.getElementById("pushMessage").innerHTML = message + "<p>";
        document.getElementById("pushData").innerHTML = JSON.stringify(event.notification) + "<p>";

        //dump custom data to the console if it exists
        if (typeof(userData) != "undefined") {
            console.warn('user data: ' + JSON.stringify(userData));
        }
    }
);

//initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
pushNotification.onDeviceReady({
    projectid: "134948189079",
    appid: "4C493-4D2ED",
    serviceName: ""
});

//register for push notifications
pushNotification.registerDevice(
    function(status) {
        alert("working")
        onPushwooshInitialized(pushNotification);

    },
    function(status) {
        alert("failed to register: " + status);
        console.warn(JSON.stringify(['failed to register ', status]));
    }
);

}

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 explicity call 'app.receivedEvent(...);' onDeviceReady: function() { initPushwoosh(); app.receivedEvent('deviceready'); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id);

    console.log('Received Event: ' + id);
}

};

app.initialize();

`

so i must get this code if i didn't allow the push

alert("failed to register: " + status);

but the problem it's still working and return the device token

so please how can i catch this case so i can append some action or close the app untill he authorized the push

DimanAM commented 7 years ago

If user does not allow application to receive notifications it can still receive silent pushes (pushes without alert, badges and sound) if application has "Background Modes" capability. So it is not the error case of push registration and application successfully receives push token. getRemoteNotificationStatus() (specifically "pushAlert" property) can be used to determine whether user allowed application to show notifications.

int3rnet commented 7 years ago

many thnx @DimanAM

So what is the cases caused the pushwoosh token didn't generated !!!

i been saving pushwoosh token for users for a long time , some users doesn't have token

doesn't means he disallowed the push notification or the pushwoosh plugin didn't recognize the phone !???

thnx

wfhm commented 6 years ago

@int3rnet is this issue still present?

Please note that we could not reproduce the issue with missing push tokens with latest Pushwoosh plugin version.

Could you please check the guide below and let us know if there are any differences between it and your Pushwoosh integration?

https://docs.pushwoosh.com/docs/cordova-phonegap