アプリにプッシュ通知を配信するために infobip を使用していますが、それが非常に強力であることは認めざるを得ません。とにかく質問があります。cordova プラグインは正常に動作しますか? アプリがプッシュ オブジェクトを認識しないためです (明らかにプラグインがインストールされています)。別の質問、アプリのすべての 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 は正しいです。