Domanda

In my iOS App i want to send an message to the watch like this:

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

If i am sending it like this it works. But if my string is longer or if i add more than 3 or 4 keys to the dictionary the message will not be delivered. Error is "the app did not acknowledge the message in time".

In my pebble App i do the following:

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

My thought is that it has something to do with the message size. But i can´t imagine that messages can only be so small? In the ToDo list example i saw that they used app_message_open with values 64 for inbox and 16 for outbox parameter. What units are meant with this? 64 characters? How do i know on the iOS side how big my message will be when it arrives on the pebble?

È stato utile?

Soluzione

First thing you should do when debugging this type of problem is adding a message_dropped handler and printing the failure reason:

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

You will find a list of reason code in the documentation.

The two most common problems are:

  1. APP_MSG_BUFFER_OVERFLOW: The message is too big (see below)
  2. APP_MSG_BUSY: You are sending messages too fast. You cannot send a new message until the previous one has been acknowledged.

The size of the message is equal to the size of the dictionary. The documentation of dict_calc_buffer_size() explains how to calculate it:

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

Finally, the values passed to app_message_open() are the buffer sizes in bytes.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top