1

On the Watch i send an AppMessage like this

DictionaryIterator *iter;
app_message_outbox_begin(&iter);
Tuplet value = TupletInteger(MESSAGE_TYPE, MESSAGETYPE_REFRESH);
dict_write_tuplet(iter, &value);
app_message_outbox_send();

I set the background modes and protocols for my app as described in the tutorial. In iOS i set the listeners like this:

[PBPebbleCentral defaultCentral].delegate = self;
self.watch = [PBPebbleCentral defaultCentral].lastConnectedWatch;

NSLog(@"Pebble name: %@", _watch.name);
NSLog(@"Pebble serial number: %@", _watch.serialNumber);

[_watch appMessagesAddReceiveUpdateHandler:^BOOL(PBWatch *watch, NSDictionary *update) {
    NSLog(@"Update received!");
    return YES;
}];

[_watch appMessagesAddReceiveAllUpdatesHandler:^BOOL(PBWatch *watch, NSUUID *uuid, NSDictionary *update) {
    NSLog(@"AllUpdate received!");
    return YES;
}];

[_watch appMessagesAddAppLifecycleUpdateHandler:^(PBWatch *watch, NSUUID *uuid, PBAppState newAppState) {
    NSLog(@"AppLifecycleUpdate received!");
}];

I already did send messages from the phone to the watch. So that way it works. But the listeners for incoming messages on the phone wont get called. On the clock i get APP_MSG_SEND_TIMEOUT as error code. What did i wrong?

4

3 回答 3

1

您的手表应用程序中有 src/js/pebble-js-app.js 吗?我有同样的问题,当我删除这个生成的文件时它开始工作。

于 2014-01-22T06:59:28.827 回答
0

注意你把听众放在哪里。例如,如果您使用的是 WeatherDemo 应用程序(由 Pebble 提供),您应该在设置应用程序 UUID 后执行此操作。

// Test if the Pebble's firmware supports AppMessages / Weather:
  [watch appMessagesGetIsSupported:^(PBWatch *watch, BOOL isAppMessagesSupported) {
    if (isAppMessagesSupported) {
      ...

        [_targetWatch appMessagesAddReceiveUpdateHandler:^BOOL(PBWatch *watch, NSDictionary *update) {
            NSLog(@"Received message: %@", update);

            return YES;
        }];
    } else {
....

另一件要注意的是不要把它放在下面, - (void)pebbleCentral:(PBPebbleCentral*)central watchDidConnect:(PBWatch*)watch isNew:(BOOL)isNew 因为如果设备已经连接,则不会调用此函数。

于 2014-04-07T13:15:15.730 回答
0

检查以确保您正在使用

appMessagesAddReceiveUpdateHandler:withUUID:

代替

appMessagesAddReceiveUpdateHandler:
于 2014-02-06T21:04:34.523 回答