如何在tizen网络应用程序上获取消息正文
How to get message body on tizen web app?
我正在为tizen开发我的第一个web应用程序,无法找到如何正确获取短信正文。试着这样做:
//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时遇到了一个问题,因为错误消息来自以下代码:
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中找到教程应用程序(Chatter)作为示例。
我发现了问题。它来自这个循环:
for (var message in messages) {
try{
MyApp.smsService.loadMessageBody(message, loadMessageBody, errorCallback);
}catch(ex) {
console.log("Get exception: " + ex.name + ":" + ex.message);
}
}
在消息变量中是空对象,所以我用ussual for循环替换了每个循环,它也发现不需要调用加载消息,它已经出现在消息对象中了。所以我使用这样的代码:
for (var i = 0; i < messages.lenght; i++) {
message = messages[i];
console.log('Body message: ' + message.body.plainText);
}
相关文章:
- KOValidation在错误消息中获取可观察值、$index()、$data等
- 在聊天记录中获取消息时间
- 服务器无法从客户端获取消息
- 对于Python,获取WebDriverException:消息:u'[JavaScript错误:“e为空”;
- 在javascript中获取NaN消息,同时添加多个文本字段
- 如果我们在5秒后有一个隐藏间隔,则无法获取Growl消息
- 如何从 store.sync();获取返回消息
- 当我只想要1时,获取返回的所有错误消息
- 如何从视频标记错误事件中获取字符串/消息或代码
- 正在获取丢失的错误处理程序套接字消息,无法读取属性'timerID'使用Node.js和Socket.i
- 如何从ajax中获取准确的错误消息
- 如何在tizen网络应用程序上获取消息正文
- 获取消息条件始终为 true
- 使用 JavaScript 获取消息正文 (Thunderbird)
- 内容脚本未获取消息
- 无法获取消息文本来呈现表情符号,而不是HTML文本
- 从javascript中的套接字获取消息时出错
- Twilio 获取消息详细信息(方法不允许)
- Facebook在工作图API,错误获取消息
- 通过js从spring资源包中获取消息