我正在构建基于API的应用程序。我使用Pebble.SendAppMessage
函数将API中的数据发送到手表。每次我尝试发送包含重音字符的数据并记录它们时,控制台都会打印以下空消息:
[xx:xx:xx] javascript>
手机和手表之间的互动不再有效。
我首先尝试将每个API数据编码为UTF8编码,但仍然会出现崩溃。
我们可以使用Pebble.SendAppMessage
函数发送包含重音的字符串吗?究竟我错过了什么?
C代码:
#include <pebble.h>
static Window *window;
static TextLayer *text_layer;
static void message_provider(DictionaryIterator* iterator, void* context) {
Tuple* tuple = dict_find(iterator, 0);
text_layer_set_text(text_layer, tuple->value->cstring);
}
static void window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_bounds(window_layer);
text_layer = text_layer_create((GRect) { .origin = { 0, 72 }, .size = { bounds.size.w, 20 } });
text_layer_set_text(text_layer, "Loading...");
text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
layer_add_child(window_layer, text_layer_get_layer(text_layer));
}
static void window_unload(Window *window) {
text_layer_destroy(text_layer);
}
static void init(void) {
window = window_create();
window_set_window_handlers(window, (WindowHandlers) {
.load = window_load,
.unload = window_unload,
});
const bool animated = true;
window_stack_push(window, animated);
app_message_register_inbox_received(message_provider);
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
}
static void deinit(void) {
window_destroy(window);
}
int main(void) {
init();
app_event_loop();
deinit();
}
JS代码:
Pebble.addEventListener("ready", function() {
Pebble.sendAppMessage({"dummy" : "Gérard example is always the best."}, function() {
console.log("message sent successfully !");
}, function() {
console.log("Cannot send message with accent.");
});
});