我正在尝试创建一个监控 iBeacons 的演示应用程序。我正在使用一个表格 View 和一个作为位置管理器委托(delegate)的自定义单元格。
我正在使用 Estimote 的信标模拟器,它允许使用 iPhone 作为信标。当应用程序运行时,位置管理器的 didRangeBeacons:
方法被调用,但没有调用其他委托(delegate)方法。我使用了 Estimote 应用程序来确保我的 iPhone 确实在广播。startMonitoringBeacon:
在父 View Controller 中创建 UITableViewCell 时调用。
这是我的自定义 UITableViewCell
@implementation PTBeaconTableViewCell
- (void)awakeFromNib {
self.locationMgr = [[CLLocationManager alloc] init];
self.locationMgr.delegate = self;
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
for(CLBeacon* beacon in beacons) {
if([_beacon isEqualToBeacon:beacon]) {
NSString* foundMsg = [NSString stringWithFormat:@"Found: %@", _beacon.uuid.UUIDString];
[self.detailLabel setText:foundMsg];
}
}
}
-(NSString*)getTimeStamp {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"hh:mm:ss"];
return [df stringFromDate:[NSDate date]];
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
NSString* message = [NSString stringWithFormat:@"Exited at %@", [self getTimeStamp]];
[self.statusLabel setText:message];
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSString* message = [NSString stringWithFormat:@"Region Entered at %@", [self getTimeStamp]];
[self.statusLabel setText:message];
}
-(CLBeaconRegion*)getRegionForBeacon:(PTBeacon*)beacon {
return [[CLBeaconRegion alloc] initWithProximityUUID:_beacon.uuid major:_beacon.major minor:_beacon.minor identifier:_beacon.name];
}
-(void)startMonitoringBeacon:(PTBeacon*)beacon {
CLBeaconRegion* region = [self getRegionForBeacon:beacon];
[self.locationMgr startMonitoringForRegion:region];
[self.locationMgr startRangingBeaconsInRegion:region];
[self.statusLabel setText:[NSString stringWithFormat:@"Monitoring began at %@", [self getTimeStamp]]];
}
-(void)stopMonitoringBeacon:(PTBeacon*)beacon {
CLBeaconRegion* region = [self getRegionForBeacon:beacon];
[self.locationMgr stopMonitoringForRegion:region];
[self.locationMgr stopRangingBeaconsInRegion:region];
[self.statusLabel setText:[NSString stringWithFormat:@"Monitoring stopped at %@", [self getTimeStamp]]];
}
@end
关于这里可能缺少什么的任何建议?谢谢!
最佳答案
尝试在您的应用程序已经启动并监控时开始播放 Estimote 应用程序。它会模拟您进入应该触发 didEnterRegion
的区域。 .另一方面,停止广播会触发 didExitRegion
.
愚蠢的问题,但尝试println()
这些方法中的日志消息。我看到您只是更新了一个标签,但它在您的 Storyboard/xib 中是否正确连接?
关于ios - 未使用 iBeacon Simulator 调用 CLLocationManager 委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32613996/