我正在使用 infobip 向我的应用程序发送推送通知,我不得不承认它非常强大。无论如何,我有一个问题。科尔多瓦插件是否正常工作?因为我的应用程序无法识别推送对象(显然已安装插件)。另一个问题,我必须在我的应用程序的所有 html 页面中的 .js 文件中初始化插件,还是足以在应用程序加载的第一个 .js 中调用初始化和注册方法?(对我来说是 index.js)这些是一些代码行
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();
我在 xCode 中遇到的错误是(不幸的是我无法上传图片:()
#import <UIKit/UIKit.h>
int main(int argc, char* argv[])
{
@autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate"); //ERROR HERE
return retVal;
}
}
我需要尽快发布这个应用程序,所以感谢您的帮助。
编辑:
我改变了一点我的代码
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');
}
所以,在这种情况下,我保存了一个局部变量,并且只有当我第一次启动应用程序时,我才设置推送参数。所有警报都可以正常工作,并且应用程序可以正常工作......但我无法收到通知 :(
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;
}
};
这是我的功能。当我使用 infobip 的面板发送通知时,事件 OnNotificationreceived 将激活......但它不是这样的。即使 onError 也不起作用,并且 senderID、applicationID 和 applicationsecret 是正确的。