【问题标题】:Messages sent with PebbleKit iOS are not received on the watch手表上收不到使用 PebbleKit iOS 发送的消息
【发布时间】:2014-01-15 20:52:45
【问题描述】:

在我的 iOS 应用程序中,我想像这样向手表发送消息:

NSMutableDictionary *message = @{@(1): @(1),
                                 @(2): @"The String"}
[_watch appMessagesPushUpdate:message onSent:^(PBWatch *watch, NSDictionary *update, NSError *error) {
  if (error != nil)
    NSLog(@"Error sending message: %@", error);
}];

如果我这样发送它,它可以工作。但是,如果我的字符串更长,或者我在字典中添加了 3 或 4 个以上的键,则消息将不会被传递。错误是“应用程序没有及时确认消息”。

在我的 pebble 应用程序中,我执行以下操作:

static void message_handler(DictionaryIterator *iter, void *context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Received message.");
  Tuple *msg_type_tuple = dict_find(iter, PebbleMessageKeyType);
  Tuple *msg_value_tuple = dict_find(iter, PebbleMessageKeyValue);
  write_line_on_screen(msg_value_tuple->value->cstring);
}
...
// Set sniff interval.
app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL); 

// Register message handlers
app_message_register_inbox_received(message_handler);
app_message_register_inbox_dropped(message_dropped);

// Init buffers
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
APP_LOG(APP_LOG_LEVEL_DEBUG, "App Message set up.");

我的想法是它与消息大小有关。但我无法想象消息只能这么小? 在ToDo list example 中,我看到他们使用 app_message_open,收件箱参数值为 64,发件箱参数值为 16。这意味着什么单位? 64个字符?在 iOS 端,我如何知道我的消息到达卵石时会有多大?

【问题讨论】:

  • 我最终通过拆分消息并通过队列发送部分来做到这一点。我在this blogpost写下了这个过程。

标签: ios pebble-watch


【解决方案1】:

调试此类问题时您应该做的第一件事是添加 message_dropped 处理程序并打印失败原因:

void init() {
   // ...
   app_message_register_inbox_dropped(appmsg_in_dropped);
   app_message_open(...);
   // ... 
}

static void appmsg_in_dropped(AppMessageResult reason, void *context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "In dropped: %i", reason);
}

您将找到原因代码in the documentation 的列表。

两个最常见的问题是:

  1. APP_MSG_BUFFER_OVERFLOW:消息太大(见下文)
  2. APP_MSG_BUSY: 你发消息太快了。在上一条消息得到确认之前,您无法发送新消息。

消息的大小等于字典的大小。 dict_calc_buffer_size() 的文档解释了如何计算它:

1 byte + 7 bytes for each key + the sum of the sizes of the values

最后,传递给app_message_open() 的值是以字节为单位的缓冲区大小。

【讨论】:

  • 谢谢!我现在得到一个错误。但是我怎么知道它是哪一个呢?我有错误代码 128。但在the documentation 中,我找不到有关哪个枚举值映射到哪个整数的信息。 (我之前发布了related question
  • 我用翻译消息中的错误代码的功能回答了您的其他问题。如果您查看pebble.h,您将看到:APP_MSG_BUFFER_OVERFLOW 等于 1 << 7,即 128。您的缓冲区对于您的消息来说太小了。
  • 相关问题在这里。 stackoverflow.com/questions/21150193/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-13
  • 1970-01-01
  • 2014-02-23
  • 1970-01-01
相关资源
最近更新 更多