首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >infobip phonegap插件崩溃

infobip phonegap插件崩溃
EN

Stack Overflow用户
提问于 2014-10-22 17:17:39
回答 2查看 182关注 0票数 0

我正在使用infobip向我的应用程序发送推送通知,我必须承认它真的很强大。不管怎样,我有一个问题。cordova插件工作正常吗?因为我的应用程序不能识别push对象(很明显插件已经安装)。另一个问题是,我是否必须在应用程序的所有html页面中的.js文件中初始化插件,或者仅在应用程序加载的第一个.js中调用初始化和注册方法就足够了?(对于我来说是index.js)以下是一些代码行

代码语言:javascript
复制
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中遇到的错误是(不幸的是我不能上传图片:( )

代码语言:javascript
复制
#import <UIKit/UIKit.h>

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

我需要尽快发布此应用程序,因此感谢您的帮助。

编辑:

我稍微修改了一下代码

代码语言:javascript
复制
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');
      }

因此,在这种情况下,我保存了一个局部变量,并且只有在第一次启动应用程序时才设置推送参数。所有警报都工作正常,并且应用程序works...but我无法收到通知:(

代码语言:javascript
复制
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的面板发送通知时,event OnNotificationreceived将activate...but它不是这样的。甚至onError也不能工作,senderID、applicationID和applicationsecret都是正确的。

EN

回答 2

Stack Overflow用户

发布于 2014-11-06 05:13:06

也许你得等ios准备好了。

我是这样初始化插件的:

代码语言:javascript
复制
document.addEventListener("deviceready", initInfoBitPlugin, false);

这对我很管用。

票数 3
EN

Stack Overflow用户

发布于 2014-10-27 19:50:20

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

您的通知侦听器中是否有onError事件?你在那里得到了什么作为论点?在onNotificationReceived中,notification参数的类型是什么?你能把它JSON.stringify到日志中吗?

你能发送一些关于这个问题的日志吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26504120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档