如何在tizen Web应用程序上获取邮件正文?

时间:2013-11-17 10:14:01

标签: javascript tizen tizen-web-app

我正在使用我的第一个网络应用程序进行tizen,无法找到如何正确获取短信邮件正文。试着这样做:

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

但是我在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

所以我在调用loadMessageBody时遇到问题,带有错误的cuase消息来自此代码:

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

我的代码出了什么问题?

2 个答案:

答案 0 :(得分:1)

目前我无法测试它是否有问题,但我建议您查看tizen.org上的教程: https://developer.tizen.org/dev-guide/2.2.1/org.tizen.web.appprogramming/html/tutorials/communication_tutorial/task_chatter_manage_message.htm

我认为你也可以在SDK中找到教程应用程序(Chatter)。

答案 1 :(得分:0)

我发现了问题。它来自这个循环:

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

在消息变量中是空对象,所以我用ussual for循环替换每个循环,也发现不需要调用load消息,它在消息对象中是alredy。所以我使用这样的代码:

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