【发布时间】: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