私はtizen用の最初のWebアプリを使用していますが、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);
しかし、私はWebシマレーターでそのような出力をコンソールから取得します。
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);
}
私のコードの何が問題になっていますか?
私は問題を見つけました。それはこのサイクルから始まります:
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);
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加