【发布时间】:2015-09-14 13:34:57
【问题描述】:
我正在尝试在没有用于测试的实际信标的开发环境中实施 iBeacon。我正在使用“Beacon Bits”,它是在 iPad 上运行的模拟器。我已经尝试过其他信标模拟器来消除模拟器可能是问题的可能性。所以,我使用的是在 iPad 上运行的模拟器,而我的应用程序在 iPhone 上运行。我没有使用 XCode 模拟器,两者都是实际设备。
我添加了在 iOS8 中似乎需要的必要位置管理器授权。我还确保这些都在我的 plist 中。
我已经仔细检查了在模拟器和运行应该检测信标模拟器的应用程序的设备上都启用了蓝牙。
当我运行应用程序时,没有响应,并且没有触发任何位置管理器委托方法。这是我的视图控制器的代码:
-(void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]){
[self.locationManager requestAlwaysAuthorization];
}
if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
[self.locationManager requestWhenInUseAuthorization];
}
uuid = [[NSUUID alloc] initWithUUIDString:UUID_STRING];
self.region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:BEACON_NAME];
[self.locationManager startMonitoringForRegion:self.region];
[_responseLabel setText:@"Waiting..."];
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
[self.locationManager startRangingBeaconsInRegion:self.region];
NSString* foundMessage = [NSString stringWithFormat:@"Region Entered for: %@", BEACON_NAME];
[_responseLabel setText:foundMessage];
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
[self.locationManager stopRangingBeaconsInRegion:self.region];
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
[_responseLabel setText:@"BEACON FOUND"];
CLBeacon* foundBeacon = [beacons firstObject];
NSString* foundMessage = [NSString stringWithFormat:@"Beacon Found: %@", BEACON_NAME];
[_responseLabel setText:foundMessage];
}
关于为什么这没有响应的任何建议?谢谢!
【问题讨论】:
-
你的macbook支持BLE(蓝牙低功耗)吗?
-
你不能用模拟器测试。使用一些设备。 stackoverflow.com/questions/22109083/…
-
我没有使用 XCode 模拟器进行测试。我的信标模拟器和我的应用程序都在物理设备上运行。
-
我的建议:实现位置管理器委托的 didChangeAuthorization 和 didFail 方法。也许你会得到更多信息
标签: ios objective-c ibeacon