Как получить тело сообщения в веб-приложении tizen?

Я работаю со своим первым веб-приложением для tizen и не могу понять, как правильно получить тело sms-сообщения. Попробуйте сделать это так:

//Initialize function
var init = function () {
    console.log("init() called");

    // add eventListener for tizenhwkey
    document.addEventListener('tizenhwkey', function(e) {
        if(e.keyName == "back")
            tizen.application.getCurrentApplication().exit();
    });    
};


$(document).ready(init);

var MyApp = {};

var smsService;
//Define the success callback.
var messageSentCallback = function(recipients) {
  console.log("Message sent successfully to " + recipients.length + " recipients.");
}

// Define the error callback.
function errorCallback(err) {
  console.log(err.name + " error: " + err.message);
}

// Define success callback
function successCallback() {
  console.log("Messages were updated");
}

//Define success callback
function loadMessageBody(message) {
    console.log ("body for message: " + message.subject + "from: " + message.from + "loaded.");
}

function messageArrayCB(messages) {
    console.log('Messages: ' + messages.length);
    for (var message in messages) {
    try{
            MyApp.smsService.loadMessageBody(message, loadMessageBody, errorCallback);
        }catch(ex) {
            console.log("Get exception: " + ex.name + ":" + ex.message);
        }
    } 
} 

function serviceListCB(services) { 

    MyApp.smsService = services[0]; 
    MyApp.smsService.messageStorage.findMessages( 
    new tizen.AttributeFilter("type", "EXACTLY", "messaging.sms"), messageArrayCB); 
} 

console.log("run"); 
tizen.messaging.getMessageServices("messaging.sms", serviceListCB, errorCallback);

Но я получаю такой вывод на консоли в веб-симуляторе:

run main.js:88
init() called main.js:4
Messages: 10 main.js:50
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58

Итак, у меня проблема при вызове loadMessageBody, сообщение cuase с ошибкой исходит из этого кода:

    try{
        MyApp.smsService.loadMessageBody(message, loadMessageBody, errorCallback);
    }catch(ex) {
        console.log("Get exception: " + ex.name + ":" + ex.message);
    }

Что не так с моим кодом?


person sphinks    schedule 17.11.2013    source источник


Ответы (2)


В настоящее время я не могу протестировать его, чтобы определить, что не так, но я бы рекомендовал проверить руководство на tizen.org: https://developer.tizen.org/dev-guide/2.2.1/org.tizen.web.appprogramming/html/tutorials/communication_tutorial/task_chatter_manage_message.htm

Думаю, вы также можете найти обучающее приложение (Chatter) в качестве образца в SDK.

person Paul S.    schedule 17.11.2013
comment
Полезная ссылка, спасибо. Я тоже вижу это приложение, но похоже, что я использую тот же код, тем не менее проблемы были в js, а не в tizen api. - person sphinks; 19.11.2013

Я нашел проблемы. Это происходит из этого цикла:

for (var message in messages) {
    try{
        MyApp.smsService.loadMessageBody(message, loadMessageBody, errorCallback);
    }catch(ex) {
        console.log("Get exception: " + ex.name + ":" + ex.message);
    }
}

В переменной сообщения был пустой объект, поэтому я заменяю для каждого цикла обычный цикл for, также он обнаруживает, что нет необходимости вызывать сообщение загрузки, оно уже присутствует в объекте сообщения. Поэтому я использую такой код:

for (var i = 0; i < messages.lenght; i++) {
    message = messages[i];
    console.log('Body message: ' + message.body.plainText);
}  
person sphinks    schedule 19.11.2013