线程1:生成EXC_BAD_ACCESS(Code = 1,address = 0x0)问题

时间:2016-02-08 12:01:55

标签: ios xcode ibm-mobilefirst mqtt hybrid-mobile-app

我正在使用Paho MQTT(物联网)和mobilefirst 7.1进行混合应用程序开发(适用于iOS,Android和Windows手机设备)。我尝试使用'broker.mqttdashboard.com'来获取MQTT代理,但它不能用于iOS。

错误:

Xcode控制台:

  

libc ++ abi.dylib:纯虚函数叫做!

main.js:

function wlCommonInit(){
     MQTTconnect(); //connect broker with subscribe 
}

mqttService.js:

var host = 'broker.mqttdashboard.com';
var port = 8000;
var topic = 'Sensor';   // topic to subscribe to
var useTLS = false;
var username = null;
var password = null;
// username = "Nazmul";
// password = "Kp0582!";
var cleansession = true;   

var mqtt;
    var reconnectTimeout = 2000;

    function MQTTconnect() {
        mqtt = new Paho.MQTT.Client(
                        host,
                        port,
                        "web_" + parseInt(Math.random() * 100,
                        10));
        var options = {
            timeout: 3,
            useSSL: useTLS,
            cleanSession: cleansession,
            onSuccess: onConnect,
            onFailure: function (message) {
                console.log("Connection failed: " + message.errorMessage + "Retrying")
                setTimeout(MQTTconnect, reconnectTimeout);
            }
    };

        mqtt.onConnectionLost = onConnectionLost;
        mqtt.onMessageArrived = onMessageArrived;

        if (username != null) {
            options.userName = username;
            options.password = password;
        }
        console.log("Host="+ host + ", port=" + port + " TLS = " + useTLS + " username=" + username + " password=" + password);
        mqtt.connect(options);
    };

    function onConnect() {

        console.log('Connected to ' + host + ':' + port)
        // Connection succeeded; subscribe to our topic
        mqtt.subscribe(topic, {qos: 0});

    };

    function onConnectionLost(response) {
        setTimeout(MQTTconnect, reconnectTimeout);

        console.log("connection lost: " + responseObject.errorMessage + ". Reconnecting")

    };

    function onMessageArrived(message) {

        var topic = message.destinationName;
        var payload = message.payloadString;

        console.log( topic + ' = ' + payload)
        alert(topic + ' = ' + payload);

    };

MobileFirst:版本7.1.0.00-20151114-1616

xcode:版本7.2 beta(7C46t)

iphone 6s plus

项目已在此处上传:https://github.com/nazmulkp/Mqtt-MobileFirst-Hybrid-Application

谢谢

3 个答案:

答案 0 :(得分:0)

int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
return retVal;

答案 1 :(得分:0)

请验证您的appdelegate类名称。是MyAppDelegate吗?如果是这样,导入MyAppDelegate.h 就可以了。如果仍然无法正常工作,请使用此代码替换您的代码。

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));
    }
}

答案 2 :(得分:0)

它是一个空引用错误,编辑器没有捕获 - 它只能在iPhone上可用的代码中运行。

空引用错误:因为javascript文件总是没有加载。抛出此错误的对象。

现在这种方式正常运作

main.js:

function wlCommonInit(){

      $(document).ready(function(){
           MQTTconnect(); //connect broker with subscribe         
       });

  }