我正在尝试为我的应用添加 iBeacon 支持。我没有任何物理 iBeacon,所以我在另一部 iPhone 上使用 Radius Networks 的 Locate 应用程序。使用该应用程序,我可以看到其他手机的信标。但是,在我自己的应用程序中,didRangeBeacons 永远不会被调用。我确保将 CoreLocation 和 CoreBluetooth 框架添加到我的应用程序中。有什么想法吗?
这是我的代码:
- (instancetype)init
{
self = [super init];
if (self)
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.discoveryUUID = [[NSUUID alloc] initWithUUIDString:@"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"];
self.region = [[CLBeaconRegion alloc] initWithProximityUUID:self.discoveryUUID identifier:[self.discoveryUUID UUIDString]];
[self.locationManager startRangingBeaconsInRegion:self.region];
self.timer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:LocatorTimeInSec] interval:0 target:self selector:@selector(timerElapsed:) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
}
return self;
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{ ... }
最佳答案
好的,我在 app-Info.plist 文件中遗漏了以下内容。我想对于 iOS 8 你需要它......
<key>NSLocationWhenInUseUsageDescription</key>
<string>This will allow you to...</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This will allow you to...</string>
我需要添加以下代码:
if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestAlwaysAuthorization];
}
关于ios - iBeacon : didRangeBeacons not being called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29458377/