这是我使用 iPhone iOS 9 检测 Eddystone 的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
if ([CLLocationManager locationServicesEnabled]) {
_locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
[self.locationManager requestAlwaysAuthorization];
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"f7826da6-4fa2-4e98-8024-bc5b71e0893e"];
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:bundleIdentifier];
self.locationManager.allowsBackgroundLocationUpdates = YES;
[self.locationManager startMonitoringForRegion:beaconRegion];
[self.locationManager startRangingBeaconsInRegion:beaconRegion];
[self.locationManager startUpdatingLocation];
}
else {
NSLog(@"location service is disabled");
}
}
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(nonnull NSArray<CLBeacon *> *)beacons
inRegion:(nonnull CLBeaconRegion *)region
{
NSLog(@"beacons count: %lu", (unsigned long)[beacons count]); // beacons count always "0"
}
我还添加了 plist NSLocationAlwaysUsageDescription 字段。
问题是它无法检测到任何带有上述代码的 Eddystone 设备。但是对于第三方应用程序,它发现很好。
我做错了什么?