0

I'm using infobip to deliver push notifications to my apps and i have to admit that it is really powerful. Anyways i've got a question. Does the cordova plugin work properly? Because my app doesn't recognize the push object (obviously the plugin is installed). Another question, Must I initialize the plugin in a .js file in all the html page of my app or is enough to call the initialize and register method only in the first .js that the app loads? (index.js for me) These are some code rows

var senderId1 = "", applicationId1, applicationSecret1;

function notificationListener(event, notification){
    switch(event){
        case ("onNotificationReceived"):
            alert(notification.title);
            break;
        case ("onInvisibleNotificationReceived"):
            // TODO your code here
            break;
        case ("onNotificationOpened"):
             window.location.href = "promo.html";
            break;
        case ("onUnregistered"):
            // TODO your code here
            break;
        case ("onRegistered"):
            // TODO your code here
            break;
        case ("onError"):
            // TODO your code here
            break;
        default:
            // TODO your code here
            break;
    }
};

//inside the 'onDevideReady' function
if (getMobileOperatingSystem() == 'Android') {
        senderId1 = "012345";
        applicationId1 = "djdjdjdjdjdj";
        applicationSecret1 = "0123456789abcd";
    } else {
        applicationId1 = "djdjdjdjdjdj";
        applicationSecret1 = "0123456789abcd";
        push.setBackgroundLocationUpdateModeEnabled(true);
    }
    //pushnotification
    push.initialize(notificationListener);

    var text =  '{' +
                  '"regData": {' +
                      ' "applicationId": "' + applicationId1 + '",' +
                      ' "applicationSecret": "' + applicationSecret1 + '",' +
                      ' "senderId": "' + senderId1 + '"' +
                  '}' +
                 '}';

    var regData = JSON.parse(text);
    push.register(regData);
    push.enableLocation();

The error i had in xCode is (unfortunately i can't upload an image :( )

#import <UIKit/UIKit.h>

int main(int argc, char* argv[])
{
    @autoreleasepool {
        int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate"); //ERROR HERE
        return retVal;
    }
}

I need to publish this app as soon as possible so thanks for the help.

EDIT:

I change a little my code

plug = window.localStorage.getItem("enable");
      alert(plug);
      if (plug == null) {
        //pushnotification
        push.initialize(notificationListener());

        alert('here');

        if (getMobileOperatingSystem() == 'Android') {
          senderId1 = "902945349798";
          applicationId1 = "ftscfg8eb5kr";
          applicationSecret1 = "qowk5x0q93a30az";
        } else {
            applicationId1 = "ftscfg8eb5kr";
            applicationSecret1 = "qowk5x0q93a30az";
            //enable the background location
            push.setBackgroundLocationUpdateModeEnabled(true);
        }

        alert('here2');
/*
          var text =  '{' +
                        '"regData": {' + 
                            ' "applicationId": "' + applicationId1 + '",' +
                            ' "applicationSecret": "' + applicationSecret1 + '",' +
                            ' "senderId": "' + senderId1 + '"' +
                        '}' + 
                       '}';

          var regData = JSON.parse(text);
*/
          //register the push
          push.register({
            senderId: senderId1,
            applicationId: applicationId1,
            applicationSecret: applicationSecret1

          });

          alert('here3');
          //enable the location
          push.enableLocation();


          window.localStorage.setItem('enable', '1');
          alert('here4');
      }

So, in this case i save a local variable and only if it's the first time i launch the app i set the push parameters. All the alerts works fine and the app works...but i can't receive the notification :(

function notificationListener (event, notification){
    switch(event){
        case ("onNotificationReceived"):
            alert(notification.title);
            break;
        case ("onInvisibleNotificationReceived"):
            // TODO your code here
            break;
        case ("onNotificationOpened"):
             window.location.href = "promo.html";
            break;
        case ("onUnregistered"):
            // TODO your code here
            break;
        case ("onRegistered"):
            // TODO your code here
            break;
        case ("onError"):
            // TODO your code here
            alert(notification);
            break;
        default:
            // TODO your code here
            break;
    }
};

This is my function. When i send a notification using infobip's panel the event OnNotificationreceived will activate...but it's not like this. Even onError doesn't work and the senderID, applicationID and applicationsecret are correct.

msmolcic
  • 6,407
  • 8
  • 32
  • 56
  • So, some time passed, what was the solution? What was the problem with the "push" object not being recognized? – wassimans Apr 22 '15 at 14:14
  • Sorry guys, the right way to do it is @debiasej solution. My problem was the call method that never fired. – BlackShawarna Apr 26 '15 at 14:22
  • That's not the question but in the end i passed with Microsoft Azure, i created a notification hub and yes, i work a little but the cost is cheaper. – BlackShawarna Apr 26 '15 at 14:23

2 Answers2

3

Maybe you have to wait for ios is ready.

I initialized the plugin this way:

document.addEventListener("deviceready", initInfoBitPlugin, false);

It works for me.

debiasej
  • 980
  • 1
  • 14
  • 26
0

It should be enough to initialize plugin only once.

Do you get onError event in your notification listener? What do you get as a argument there? In onNotificationReceived, what is the type of notification argument? Could you JSON.stringify it to logs?

Can you send some logs surrounding this issue?

maricn
  • 593
  • 1
  • 6
  • 21
  • Hi! Check my edit! One question, i really need to make it work because i've got a presentation in a few days. Is it possible to call you? – BlackShawarna Nov 01 '14 at 15:16