iBeacon显示:didRangeBeacons停止获取调用,必须重置设备后才能继续工作 [英] iBeacon: didRangeBeacons stops getting called, must reset device for it to work again

查看:516
本文介绍了iBeacon显示:didRangeBeacons停止获取调用,必须重置设备后才能继续工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是自定义的BeaconManager委托,使航标范围不是由视图控制器的生命周期决定的。一切都很正常,但每过一段时间(1-2天)灯塔范围将停止工作,并didRangeBeacons将永远不会被调用。解决这个问题的唯一方法是让我重新设置我的iPhone,一旦我做到这一点,它完美的作品。下面是code,我使用。基本流程是,当我的ViewController调用viewDidLoad中发送一个通知回到AppDelegate中,告诉它开始测距航标,我从来没有告诉它停​​下来,然后,因为我希望它继续区间信标无论身在何处,用户导航在应用程序。我如果这仅仅是一个带有蓝牙错误想知道如果我的code是导致此。感谢您的帮助!

BeaconManager.m

 #进口BeaconManager.h
#进口AppDelegate.h@interface BeaconManager()< CLLocationManagerDelegate>@属性(非原子,强)CLLocationManager *的LocationManager;
@属性(非原子,强)CLBeaconRegion * beaconRegion;@结束@implementation BeaconManager+(id)的sharedManager
{
    静态BeaconManager * sharedBeaconManager =零;
    静态dispatch_once_t一次;
    dispatch_once(安培;一次,^ {
        sharedBeaconManager = [[自我的alloc]初始化];
    });
    返回sharedBeaconManager;
} - (ID)的init
{
    自= [超级初始化]
    如果(个体经营)
    {
        self.locationManager = [[CLLocationManager的alloc]初始化];
        self.locationManager.delegate =自我;
    }
    返回自我;
} - (无效)startBeaconMonitoring:(* NSString的)forUUID
{
    NSUUID * UUID = [[NSUUID页头] initWithUUIDString:forUUID];    self.beaconRegion = [[CLBeaconRegion页头] initWithProximityUUID:UUID标识:@com.beacons.publicRegion];
    [self.locationManager startMonitoringForRegion:self.beaconRegion];
    [self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
} - (无效)stopBeaconMonitoring
{
    //停止区域监控
    如果(self.locationManager =零和放大器;!&安培;!self.beaconRegion =无){
        [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
    }
}的#pragma马克 - CLLocationManagerDelegate - (无效)的LocationManager:(CLLocationManager *)经理didRangeBeacons:(NSArray的*)标inRegion:(CLBeaconRegion *)区域
{
    self.beacons =信标;
    如果(self.delegate!=无){
        [self.delegate beaconManager:自didRangeBeacons:self.beacons];
    }
}@结束

ViewController.m

  @implementation的ViewController - (无效)viewDidLoad中
{
    [超级viewDidLoad中];    [NSNotificationCenter defaultCenter] postNotificationName:@startRanging的对象:无用户信息:无];
}

AppDelegate.m

   - (BOOL)应用:(*的UIApplication)的应用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions
{
    [NSNotificationCenter defaultCenter]的addObserver:自我选择:@selector(startRangingForZombies)名称:@startRanging的对象:无];    返回YES;
} - (无效)startRanging
{
    //启动信标区域的监控,当控制器的负载
    BeaconManager * beaconManager = [BeaconManager sharedManager]
    beaconManager.delegate =自我;
    [beaconManager startBeaconMonitoring:@1234-54324-34242-34242-43243];
}


解决方案

我们已经收到了许多报告,在半径网络电话再次停止检测iBeacons并需要重新启动或关闭蓝牙和背部上解决问题的。乡亲们已举报此对iPhone 4S的,iPhone 5S,iPhone 5C和iPad。

我没有任何确凿的证据证明这是一件破作为iOS的7.1,但报告的频率已经自发布以来一路上扬。因此,旁证是pretty强。

当这款手机进入这种状态下,手机<一个href=\"http://stackoverflow.com/questions/22853773/ios-app-with-ibeacon-must-restart-device/22862781?noredirect=1#comment35037180_22862781\">can仍然扫描蓝牙设备,而且还可以传输作为iBeacon显示。因此,它不是一个硬件问题蓝牙。根据现有的证据,这是最有可能在CoreLocation新引入的错误。

I am using a custom BeaconManager delegate so that beacon ranging is not determined by the life-cycle of the view controller. Everything works great but every once in a while (1-2 days) beacon ranging will stop working and didRangeBeacons will never get called. The only way to fix this is for me to reset my iPhone, once I do this, it works perfectly. Below is the code that I am using. The basic flow is that when my ViewController calls ViewDidLoad it sends a notification back to the AppDelegate to tell it to start ranging for beacons, I never tell it to stop then because I want it to continue to range for beacons no matter where the user navigates to in the app. I'm wondering if my code is causing this or if this is just a bug with Bluetooth. Thanks for your help!

BeaconManager.m

#import "BeaconManager.h"
#import "AppDelegate.h"

@interface BeaconManager()<CLLocationManagerDelegate>

@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) CLBeaconRegion *beaconRegion;

@end

@implementation BeaconManager

+ (id)sharedManager
{
    static BeaconManager *sharedBeaconManager = nil;
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        sharedBeaconManager = [[self alloc] init];
    });
    return sharedBeaconManager;
}

- (id)init
{
    self = [super init];
    if(self)
    {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
    }
    return self;
}

- (void)startBeaconMonitoring:(NSString*)forUUID
{
    NSUUID * uuid = [[NSUUID alloc] initWithUUIDString:forUUID];

    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"com.beacons.publicRegion"];
    [self.locationManager startMonitoringForRegion:self.beaconRegion];
    [self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}

- (void)stopBeaconMonitoring
{
    //Stop the region monitoring
    if(self.locationManager != nil && self.beaconRegion != nil) {
        [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
    }
}

#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
    self.beacons = beacons;
    if(self.delegate != nil) {
        [self.delegate beaconManager:self didRangeBeacons:self.beacons];
    }
}

@end

ViewController.m

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"startRanging" object:nil userInfo:nil];
}

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startRangingForZombies) name:@"startRanging" object: nil];

    return YES;
}

- (void)startRanging
{
    //Start the beacon region monitoring when the controller loads
    BeaconManager *beaconManager = [BeaconManager sharedManager];
    beaconManager.delegate = self;
    [beaconManager startBeaconMonitoring:@"1234-54324-34242-34242-43243"];
}

解决方案

We have received many reports at Radius Networks of phones stopping detecting iBeacons and requiring a reboot or turning Bluetooth off and back on again to resolve the situation. Folks have reported this on iPhone 4S, iPhone 5s, iPhone 5c and iPads.

I do not have any hard evidence that this is something that broke as of iOS 7.1, but the report frequency has gone way up since its release. The circumstantial evidence is therefore pretty strong.

When this phone gets into this state, the phone can still scan for bluetooth devices, and can still transmit as an iBeacon. It is therefore not a hardware problem with Bluetooth. Based on the available evidence, it is most likely a newly introduced bug in CoreLocation.

这篇关于iBeacon显示:didRangeBeacons停止获取调用,必须重置设备后才能继续工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆