我正在嘗試創建一個監視iBeacons的演示應用程序。我正在使用一個表視圖和一個位置管理器委託的自定義單元格。未使用iBeacon模擬器調用CLLocationManager委託方法
我使用的是允許使用的是iPhone的一盞明燈Estimote的燈塔模擬器。當應用程序運行時,位置管理器的didRangeBeacons:
方法被調用,但沒有其他委託方法被調用。我已經使用了Estimote應用來確保我的iPhone絕對是廣播。
startMonitoringBeacon:
在父視圖控制器被創建的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
什麼可能丟失在這裏有什麼建議?謝謝!
是,細胞被正確渲染,我已經在你提到的位置設置斷點和他們從不打 – Pheepster
開始演示程序幫助後啓動estimote應用程序,我收到關於輸入區域的通知。 – Pheepster