簡體   English   中英

如何在tizen Web應用程序上獲取消息正文?

[英]How to get message body on 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中得到了這樣的om控制台輸出:

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時遇到問題,請從以下代碼中獲取錯誤消息:

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

我的代碼有什么問題?

目前,我無法對其進行測試以判斷出問題所在,但我建議您查看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中找到教程應用程序(章節)作為示例。

我發現了問題。 從這個周期開始:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM