ios - iBeacon : didRangeBeacons not being called

标签 ios core-bluetooth

我正在尝试为我的应用添加 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/

相关文章:

ios - 带有 EncryptedCoreData 的架构 i386 的 undefined symbol

在 iOS 自定义键盘中使用时,iOS CoreBluetooth 状态不受支持

ios - CoreBluetooth 应用程序在后台究竟能做什么?

swift - 如何在后台广播蓝牙信号,然后在 Swift 中运行前台时发现该设备?

iOS:捆绑显示名称

ios - 在 iOS 上逐字显示文本

ios - 错误 : Cannot convert value of type '(_, _) -> Void' to expected argument type '((UIAlertAction) -> Void)?'

ios - 在 View 之间传递核心数据实体变量

ios CBCentralManager DidDiscoverPeripheral

iOS Corebluetooth 扫描速率