我有一个旧的Pebble Classic手表,升级到最新的固件(3.8.2),并使用最新的Pebble-SDK。
我已经按照下面几个简单的步骤安装了SDK,设置了一个Xcode项目,并添加了初始化和连接的代码:https://developer.getpebble.com/guides/mobile-apps/ios/
我的问题是,委托方法pebbleCentral:watchDidConnect从不被调用!
我正在使用iPad上的Pebble Time应用程序在手表中安装watchApp,所以我知道iPad已经连接到手表上了。运行iOS应用程序的是同一个iPad,该应用程序显然不会发现手表。
我试着从一位同事那里导入一个旧的测试项目,他在一两年前运行了它。同样的手表,同样的watchApp,当然还有更老的固件和软件开发工具包版本。同样的结果。
我认为pebble网站上的文档非常简单易懂。然而,我觉得我遗漏了一些关于这个watchDidConnect应该如何以及何时触发的解释。
我很可能在某个地方遗漏了一些简单的步骤,但我完全迷失在哪里去寻找!
欢迎任何想法!
编辑:我的代码看起来像这样:
ViewController.h:
#import <UIKit/UIKit.h>
@import PebbleKit;
@interface ViewController : UIViewController<PBPebbleCentralDelegate>
@endViewController.m:
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) PBWatch* connectedWatch;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[PBPebbleCentral defaultCentral].delegate = self;
[[PBPebbleCentral defaultCentral] run];
NSLog(@"Pebble initialised");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)pebbleCentral:(PBPebbleCentral*)central watchDidConnect (PBWatch*)watch isNew:(BOOL)isNew {
NSLog(@"Pebble connected: %@", [watch name]);
self.connectedWatch = watch;
}
- (void)pebbleCentral:(PBPebbleCentral*)central watchDidDisconnect:(PBWatch*)watch {
NSLog(@"Pebble disconnected: %@", [watch name]);
if ([watch isEqual:self.connectedWatch]) {
self.connectedWatch = nil;
}
}
@end发布于 2016-01-27 17:26:34
在设置好Pebble central之后,您是否正在调用-run方法?我注意到您发布的链接中的代码片段没有显示设置中心的delegate。
[PBPebbleCentral defaultCentral].delegate = self; // Set your delegate
[PBPebbleCentral defaultCentral].appUUID = [[NSUUID alloc] initWithUUIDString:@"Your Pebble App UUID"]; // Set the app UUID
[[PBPebbleCentral defaultCentral] run]; // Call -run on the central
https://stackoverflow.com/questions/35033072
复制相似问题