为什么间歇性地调用didEnterRegion委托?

时间:2017-05-05 09:14:59

标签: ios cllocationmanager ibeacon

这是对Why is didEnterRegion not called

的问题的跟进

现在,didEnterRegion调用“有时”,但并非总是如此,如果我删除应用程序,安装应用程序并关闭信标,然后启动它大部分时间工作的信标,我的调试显示所有正确的信息但它只是不可靠。

我知道100%信标是好的并且广播,因为我在设置旁边有一个信标扫描仪,我看到它直接在我的命令上打开和关闭

这是我的完整代码,没有遗漏任何内容

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    // Initialize location manager and set ourselves as the delegate
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    NSLog(@"authstate changed was hit wit status %d", status);

    if (status == kCLAuthorizationStatusAuthorizedAlways) {
        // Create a NSUUID with the same UUID as the broadcasting beacon
        NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"39876A4B-43B2-4BE8-9A9C-41BAE913D56A"];

        // Setup a new region with that UUID and same identifier as the broadcasting beacon
        _myBeaconRegion= [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                            identifier:@"me.netwizards.office"];

        [_locationManager startMonitoringForRegion:_myBeaconRegion];
        NSLog(@"location Manager started to monitor regions: %@", self.locationManager.monitoredRegions);
    } else {
        [self.locationManager requestAlwaysAuthorization];
        NSLog(@"requesting again");
    }
}


- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"Error : %@",error);
}

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
    NSLog(@"Region monitoring failed with error: %@", [error localizedDescription]);
}

- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion*)region
{
    NSLog(@"Did Enter Region");
    [self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];
}

-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion*)region
{
    [self.locationManager stopRangingBeaconsInRegion:self.myBeaconRegion];
    self.viewControllerStoreLbl.text = @"No Store Detected";
    self.viewControllerOpeningTimesLbl.text = @"No Store Detected";
    NSLog(@"Did Exit Region");
}

-(void)locationManager:(CLLocationManager*)manager
       didRangeBeacons:(NSArray*)beacons
              inRegion:(CLBeaconRegion*)region
{
    // Beacon found!
    self.viewControllerStoreLbl.text = @"Matts Test Store";
    self.viewControllerOpeningTimesLbl.text = @"Open 9 AM to 9 PM";

    CLBeacon *foundBeacon = [beacons firstObject];

    // You can retrieve the beacon data from its properties
    NSString *uuid = foundBeacon.proximityUUID.UUIDString;
    NSString *major = [NSString stringWithFormat:@"%@", foundBeacon.major];
    NSString *minor = [NSString stringWithFormat:@"%@", foundBeacon.minor];

    NSLog(@"Beacon Data: UUID: %@, major: %@, minor: %@", uuid, major, minor);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

这是调试显示区域监控启动很好,位置管理器Auth委托被称为ok并按预期工作

2017-05-05 17:05:45.102718 NW SelfCheckout[225:4033] authstate changed was hit wit status 0
2017-05-05 17:05:45.104175 NW SelfCheckout[225:4033] requesting again
2017-05-05 17:05:47.314500 NW SelfCheckout[225:4033] authstate changed was hit wit status 3
2017-05-05 17:05:47.327998 NW SelfCheckout[225:4033] location Manager started to monitor regions: {(
    CLBeaconRegion (identifier:'me.netwizards.office', uuid:39876A4B-43B2-4BE8-9A9C-41BAE913D56A, major:(null), minor:(null))
)}

但之后没有任何反应,我可以等待数小时,打开和关闭信标从范围中移除信标等没有任何使它工作,重启设备仍然没有帮助

可能出现什么问题?

0 个答案:

没有答案