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.