Pebble return carriages 在模拟器上工作,但在 watch 上不工作

Pebble return carriages working on emulator but not on watch

我有一个 Pebble 智能手表表盘,它从应用程序配置页面(html 页面)的文本区域获取文本,并将该值放入表盘上的文本层。

不幸的是,有两件事导致它无法按预期工作(希望它们都能用一种解决方案解决):

1) Return carriages (eg. \n 不适用于文本层,而不是移动到一个新行它只显示 '\n' 字符 2) 未配对的 '(撇号)和 "(引号)不更新页面(即不起作用)

我并不擅长处理我的表盘和配置之间的通信,但除了这个问题之外,其他一切似乎都运行良好。下面是我将文本从文本区域获取到文本层的路径。

相关脚本(在config.html)

[].forEach.call(document.querySelectorAll("#save"), function(e1) {
                e1.addEventListener("click", function() {
                    console.log(saveOptions());
                    var return_to = getQueryParam('return_to', 'pebblejs://close#');
                    document.location = return_to + encodeURIComponent(JSON.stringify(saveOptions()));
                });
            });

相关 javascript (script.js)

    Pebble.addEventListener('webviewclosed', function(e) {
      var options = JSON.parse(decodeURIComponent(e.response));
      message = options.message;

var dict = {
    'MESSAGE_DATA' : message
  };

  //Send a string to Pebble
  Pebble.sendAppMessage(dict, function(e) {
    console.log("Send successful.");
  }, function(e) {
    console.log("Send failed!");
  });
}

相关main.c:

static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  APP_LOG(APP_LOG_LEVEL_INFO, "Message received!");

  // Get the first pair
  Tuple *t = dict_read_first(iterator);

  // Process all pairs present
  while(t != NULL) {
  // Process this pair's key
    switch (t->key) {
      case MESSAGE_DATA:
        snprintf(message_buffer, sizeof(message_buffer), "%s", t->value->cstring);
        APP_LOG(APP_LOG_LEVEL_INFO, "MESSAGE_DATA received with value %d", (int)t->value->int32);
        break;
      default:
        APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key);
        break;
    }

    // Get next pair, if any
    t = dict_read_next(iterator);
  }
}

编辑:添加 message.replace(/[\n\r]/g, ' '); 无法解决问题 1:/

我认为这在 JS 和 C 之间的转换中丢失了,因为 C 正确显示 return 车厢。您应该考虑使用特殊字符来替换所有 return 字符,例如 # 或 $,它们可能不会出现在您要发送的实际消息中。然后,遍历 C 中的字符数组,并将该特殊字符的所有实例替换为 \n.