문제

I'm working with my first web-app for tizen and can't find out how correctly get sms message body. Try to do it as this:

//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);

But I get such output om console in web simalator:

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

So I have a problem at call of loadMessageBody, cuase message with error comes from this code:

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

What`s wrong with my code?

도움이 되었습니까?

해결책 2

I found the problems. It goes from this cycle:

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

In message variable was empty object, so I replace for each loop with ussual for loop, also it discover that no need to call load message, it is alredy presents in message object. So I use such code:

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

다른 팁

Currently I can't test it to tell what's wrong, but I would recommend checking out the tutorial on tizen.org: https://developer.tizen.org/dev-guide/2.2.1/org.tizen.web.appprogramming/html/tutorials/communication_tutorial/task_chatter_manage_message.htm

I think you can also find the tutorial app (Chatter) as a sample in the SDK.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top