Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
109 stars 139 forks source link

no action when calling getPushHistory() !! #249

Closed int3rnet closed 7 years ago

int3rnet commented 7 years ago

Hello dear in pushwoosh

i have a code below to get the pushwoosh history for the device , i copied the code from pushwoosh documentation and try to call it but nothing happen , i called the function two times and same problem

below the code and there is a comment for the two times call

` var n

function onPushwooshInitialized(pushNotification) {

            // second call , nothing happend also
             pushNotification.getPushHistory(function(pushHistory) {
            if(pushHistory.length == 0)
                alert("no push history");
            else
                alert(JSON.stringify(pushHistory));
        });

//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);
                     pushwooshToken = token;

    },function(e) {

                alert("Failed in getPushToken");

            }

);

}

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;

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

                alert("Failed in addEventListener2");
            }
);

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

//register for push notifications

pushNotification.registerDevice(
    function(status) {

        onPushwooshInitialized(pushNotification);

        // first call , nothing happen
        pushNotification.getPushHistory(function(pushHistory) {
            if(pushHistory.length == 0)
                alert("no push history");
            else
                alert(JSON.stringify(pushHistory));
        });

    },
    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();`

int3rnet commented 7 years ago

moreover there is an error in xcode debug

2017-04-03 12:08:15.862 Ajeer-Client[2257:1030110] ERROR: Method 'getPushHistory:' not defined in Plugin 'PushNotification' 2017-04-03 12:08:15.862 Ajeer-Client[2257:1030110] -[CDVCommandQueue executePending] [Line 142] FAILED pluginJSON = ["PushNotification1858525230","PushNotification","getPushHistory",[]]

DimanAM commented 7 years ago

getPushHistory() is supported only on Android.

int3rnet commented 7 years ago

@DimanAM so what's my choices for ios and getting the push history?