我试图在我开发的表盘上添加一些配置,但是达到了完全停顿状态。配置将您带到必须选择城市的页面。我已经添加了一个app.js页面,该页面可以捕获此值&将其重定向到表盘:
Pebble.addEventListener("webviewclosed",
function(e) {
//Get JSON dictionary
var configuration = JSON.parse(decodeURIComponent(e.response));
console.log("[DBUG] Configuration window returned: " + JSON.stringify(configuration) + " " + configuration.basic);
//Send to Pebble, persist there
Pebble.sendAppMessage(
{'KEY_CITY': configuration.basic},
function(e) {
console.log("[DBUG] Settings data sent successfully ");
},
function(e) {
console.log("[FAIL] Settings feedback failed!");
}
);
}
);
这很好用,日志包含正确的选定城市。我还注意到调用了in_recv_handler回调函数:
[PHONE] pebble-app.js:?: Skylines__0.0/pebble-js-app.js:12 [DBUG] Configuration window returned: {"basic":"Brussels"} Brussels
[DEBUG] main.c:106: [DBUG] in_recv_handler - EMPTY TUPLE
[PHONE] pebble-app.js:?: Skylines__0.0/pebble-js-app.js:18 [DBUG] Settings data sent successfully
在我的C代码中,事情发生了可怕的错误: appmessage似乎在init()部分正确初始化:
app_message_register_inbox_received(in_recv_handler);
app_message_register_inbox_dropped(inbox_dropped);
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
in_recv_handler是问题所在:
static void in_recv_handler(DictionaryIterator *iterator, void *context) {
//Get data
Tuple *tup = dict_read_first(iterator);
if (tup != NULL) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "[DBUG] in_recv_handler - NONEMPTY TUPLE");
process_tuple(tup);
}
else { APP_LOG(APP_LOG_LEVEL_DEBUG, "[DBUG] in_recv_handler - EMPTY TUPLE"); }
}
元组/字典总是空的。所以app.js和字典加载之间似乎出现了问题,但我没有任何线索......