【问题标题】:infobip phonegap plugin crashinfobip phonegap 插件崩溃
【发布时间】:2014-10-22 09:17:38
【问题描述】:

我正在使用 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 都是正确的。

【问题讨论】:

  • 那么,过了一段时间,解决方案是什么?无法识别“推送”对象的问题是什么?
  • 对不起,正确的做法是@debiasej 解决方案。我的问题是从未触发的调用方法。
  • 这不是问题,但最后我通过了 Microsoft Azure,我创建了一个通知中心,是的,我工作了一点,但成本更便宜。

标签: android ios cordova infobip


【解决方案1】:

也许你必须等待 ios 准备好。

我是这样初始化插件的:

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

它对我有用。

【讨论】:

    【解决方案2】:

    插件初始化一次就足够了。

    您的通知侦听器中是否收到onError 事件?你在那里得到什么作为论据? 在onNotificationReceived 中,notification 参数的类型是什么?你能JSON.stringify它记录吗?

    您能否发送一些有关此问题的日志?

    【讨论】:

    • 嗨!检查我的编辑!一个问题,我真的需要让它发挥作用,因为几天后我有一个演示文稿。可以给你打电话吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-21
    • 2013-10-18
    • 1970-01-01
    相关资源
    最近更新 更多