【问题标题】:Cloud pebble does not receive data from iOS app?Cloud pebble 不接收来自 iOS 应用程序的数据?
【发布时间】:2015-06-24 05:56:08
【问题描述】:

一切都可以很好地获取手表信息,但是当我将数据 iOS 应用程序传输到手表应用程序时,有时我的日志显示消息发送成功时出现错误。即使发送了消息,我的 pebble 手表也没有收到任何数据。它只是去我的卵石手表中的空窗口。

我正在为 pebble watch 应用和 iOS 版本 8.3、xcode 6.3.1 使用 cloud pebble

c 代码:

#include <pebble.h>

static TextLayer *hello_text_layer;

static void message_received(DictionaryIterator *iterator, void *context) {

  char *message = dict_find(iterator, 0)->value->cstring;
  text_layer_set_text(hello_text_layer,message);
  text_layer_set_font(hello_text_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));


}

int main(void) {
  app_message_register_inbox_received(message_received);
  app_message_open(app_message_inbox_size_maximum(), 0);

  Window *first_window = window_create();

  hello_text_layer = text_layer_create(GRect(10, 10, 124, 148));
  text_layer_set_text(hello_text_layer, "Welcome");
  layer_add_child(window_get_root_layer(first_window), text_layer_get_layer(hello_text_layer));

  window_stack_push(first_window, true);

  app_event_loop();

  text_layer_destroy(hello_text_layer);
  window_destroy(first_window);
}

iOS 代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    self.watch = [delegate getConnectedWatch];

    // Check the watch object is available
    if(self.watch) {
        NSLog(@"i think got its work");
        [self.watch getVersionInfo:^(PBWatch *watch, PBVersionInfo *versionInfo ) {
            NSLog(@"Pebble name: %@", [watch name]);
            NSLog(@"Pebble serial number: %@", [watch serialNumber]);
            NSLog(@"Pebble firmware os version: %li", (long)versionInfo.runningFirmwareMetadata.version.os);
            NSLog(@"Pebble firmware major version: %li", (long)versionInfo.runningFirmwareMetadata.version.major);
            NSLog(@"Pebble firmware minor version: %li", (long)versionInfo.runningFirmwareMetadata.version.minor);
            NSLog(@"Pebble firmware suffix version: %@", versionInfo.runningFirmwareMetadata.version.suffix);
        } onTimeout:^(PBWatch *watch) {
            NSLog(@"Timed out trying to get version info from Pebble.");
        }];


        [self.watch appMessagesGetIsSupported:^(PBWatch *watch, BOOL isAppMessagesSupported) {
            if(isAppMessagesSupported) {
                // Tell the user using the Label
                NSLog(@"can send data to watch");
            } else {
                NSLog(@"cannot send data to watch");
            }
        }];

    }

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)send:(id)sender {

    [self.watch appMessagesLaunch:^(PBWatch *watch, NSError *error) {
        if (!error) {
            NSLog(@"Successfully launched app.");
        }
        else {
            NSLog(@"Error launching app - Error: %@", error);
        }
    }
     ];
    // Register to receive events
    [[PBPebbleCentral defaultCentral] setDelegate:self];
    // Set UUID
        uuid_t myAppUUIDbytes;
        NSUUID *myAppUUID = [[NSUUID alloc] initWithUUIDString:@"37cec7a8-8195-4b9f-9a1b-696b7e05ba1b"];
          [myAppUUID getUUIDBytes:myAppUUIDbytes];
        [[PBPebbleCentral defaultCentral] setAppUUID:[NSData dataWithBytes:myAppUUIDbytes length:16]];

    NSDictionary *message = @{@(0):@"optisol",
                              };
    NSLog(@"%@",message);
    [self.watch appMessagesPushUpdate:message onSent:^(PBWatch *watch, NSDictionary *update, NSError *error) {
        NSLog(@"getting called");
        if (!error) {
            NSLog(@"Message sent!!!!!!!!");
        }
        else
        {
            NSLog(@"Message not sent!!!!!!!!\n\n%@",error.localizedDescription);

        }


    }];

    [self.watch appMessagesAddReceiveUpdateHandler:^BOOL(PBWatch *watch, NSDictionary *update) {
        // Process incoming messages
        if([update objectForKey:[NSNumber numberWithInt:0]]) {
            // Up button was pressed!

            NSLog(@"value received form pebble");

        }



        return YES;
    }];
}

有时我也收到此错误:

Error launching app - Error: Error Domain=com.pebble.iossdk.public Code=10 "The watch did not acknowledge the pushed update in time." UserInfo=0x166b9120 {NSLocalizedDescription=The watch did not acknowledge the pushed update in time.}

【问题讨论】:

    标签: ios pebble-watch cloudpebble


    【解决方案1】:

    我终于找到了我的问题的解决方案.. Here 解释得很好。

    我已经把我的 c 代码改成这样了

    APP_LOG(APP_LOG_LEVEL_INFO, "Message received!");
        Tuple *t = dict_read_first(iterator);
    
      while (t != NULL) {
        // Long lived buffer
            static char s_buffer[64];
            APP_LOG(APP_LOG_LEVEL_INFO, "Message ready to get!");
            snprintf(s_buffer, sizeof(s_buffer), "'%s'", t->value->cstring);
            text_layer_set_text(hello_text_layer, s_buffer);
        // Get next pair, if any
        t = dict_read_next(iterator);
      }
    

    工作正常..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 2012-08-23
      相关资源
      最近更新 更多