Javascript Pebble配置页通信未响应

Javascript Pebble配置页通信未响应,javascript,json,communication,pebble-sdk,cloudpebble,Javascript,Json,Communication,Pebble Sdk,Cloudpebble,我正在创建我的第一个watchface,它需要一个配置页面,其中可以存储两个字符串(一个标题和一条消息) 我不太熟悉所有的交流方式,因为这里没有任何完整的例子,但我已经尽可能地做到这一点 这是我所有空间的相关代码 main.c static void inbox_received_callback(DictionaryIterator *iterator, void *context) { APP_LOG(APP_LOG_LEVEL_INFO, "Message re

我正在创建我的第一个watchface,它需要一个配置页面,其中可以存储两个字符串(一个标题和一条消息)

我不太熟悉所有的交流方式,因为这里没有任何完整的例子,但我已经尽可能地做到这一点

这是我所有空间的相关代码

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);

              //Long lived buffers
              static char title_buffer[64];
              static char message_buffer[124];

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

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

var title = localStorage.getItem('title') ? localStorage.getItem('title') : 'Title',
        message = localStorage.getItem('message') ? localStorage.getItem('message') : "Message that can be changed in watchface 'Settings'";

        Pebble.addEventListener('showConfiguration', function(e) {
          console.log("Showing configuration");
          // Show config page
          Pebble.openURL('https://dl.dropboxusercontent.com/s/kzl44khedt5e22d/config.html?dl=0');
        });

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

          if(title == 'undefined') {
            title = 'Title';
          } if (message == 'undefined') {
            message = "Message that can be changed in watchface 'Settings'";
          }

          localStorage.setItem('title', title);
          localStorage.setItem('message', message);

          console.log("Configuration window returned: ", JSON.stringify(options));
        });

        Pebble.addEventListener('ready', function(e) {
          console.log("PebbleKit JS Ready!");

          //Construct a dictionary
          var

 dict = {
            'TITLE_DATA' : title,
            'MESSAGE_DATA' : message
          };

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

<h3>Title:</h3>
        <input type="text" name="title" id="title"></input>
        <h3>Message:</h3>
        <input type="text" name="message" id="message"></input>  
        <br>        
        <input type="submit" id="cancelButton" value="Cancel">
        <input type="submit" id="saveButton" value="Save">

    <script>
        $('#cancelButton').click(function() {
            location.href = 'pebblejs://close';
        });

        $('#saveButton').click(function() {
            var options = {
                title: $('title').val(),
                message: $('#message').val()
            }

            location.href = 'pebblejs://close#' + encodeURIComponent(JSON.stringify(options));
        });

        function getURLVariable(name)  {
            name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
            var regexS = "[\\?&]"+name+"=([^&#]*)",
                regex = new RegExp(regexS),
                results = regex.exec(window.location.href);
            if (results == null) return "";
            else return results[1];
        }
        $(document).ready(function() {
            var priorTitle = getURLVariable('title');
            priorTitle = decodeURI(priorTitle);

            if (priorTitle) {
                $('#title').html(priorTitle);
            }

            var priorMessage = getURLVariable('message');
            priorMessage = decodeURI(priorTitle);

            if (priorMessage) {
                $('#message').html(priorMessage);
            }
        });
    </script>
标题:
信息:

$(“#取消按钮”)。单击(函数(){ location.href=pebblejs://close'; }); $(“#保存按钮”)。单击(函数(){ 变量选项={ 标题:$('title').val(), 消息:$(“#消息”).val() } location.href=pebblejs://close#'+encodeURIComponent(JSON.stringify(options)); }); 函数getURLVariable(名称){ 名称=名称。替换(/[\[]/,“\\\[”)。替换(/[\]]/,“\\\]”); var regexS=“[\\?&]”+name+“=([^&\\]*)”, regex=新的RegExp(regexS), 结果=regex.exec(window.location.href); 如果(results==null)返回“”; 否则返回结果[1]; } $(文档).ready(函数(){ var priorTitle=getURLVariable('title'); 优先级=解码URI(优先级); 如果(优先级){ $('#title').html(priorTitle); } var priorMessage=getURLVariable('message'); priorMessage=decodeURI(优先级); 如果(优先消息){ $('#message').html(priorMessage); } });
如果有人能理解为什么这不能按预期工作,我将非常感谢您的帮助:)请让我知道,如果有任何其他细节,我应该包括在内

我正在使用CloudPebble进行开发。我在设置中完成了标题和消息键,并在main.c中定义了它们,所以不是这样

我需要注意的是,在应用程序日志中,它显示“TITLE\u DATA received with value…”而不是“MESSAGE\u DATA received…”,因此问题可能就在那里。

您正在函数中声明“长寿命缓冲区”:

静态无效收件箱\u收到\u回调(字典迭代器*迭代器,无效*上下文){
...
//长寿命缓冲器
静态字符标题_缓冲区[64];
静态字符消息_缓冲区[124];
...
}
如果希望它们保留在范围内(持久化),则需要将它们与其他全局变量一起声明:

静态窗口*s_主窗口;
静态字符标题_缓冲区[64];
静态字符消息_缓冲区[124];

谢谢,前几天我修好了,忘了我发布了一个关于它的问题,但这就是问题所在:)