位置服务未请求许可

时间:2013-12-07 17:49:37

标签: ios core-location ibeacon

我有一件奇怪的事情发生。

FIXED:我在viewDidLoad方法中创建了我的CLLocationManager,所以它几乎立即被ARC清理。我将我的实例更改为类实例而不是方法实例,问题解决了。

更新:调用位置服务的视图直接显示在下方。允许弹出位置服务的请求会立即消失。

    - (void)viewDidLoad
{
    [super viewDidLoad];
    //Grab the JSON from dcJSONParser
    NSURL *mainContentURL = [NSURL URLWithString:@"http://www.andrewlarking.co.uk/DigiCons/appContent.txt"];
    dcJSONParser *mainJSONParser = [[dcJSONParser alloc]init];
    NSDictionary *mainPageDictonary = [mainJSONParser getContentFromNSURL:mainContentURL];
    //Grab the data from a specific JSON collection
    NSArray *pageOneContent = mainPageDictonary[@"firstRunPage"];
    for ( NSDictionary *pageOne in pageOneContent )
    {
        //Set the label
        self.dcEventDayViewControllerBeaconNameLabel.text = pageOne[@"title"];
    }

    NSLog(@"Event Day View Loaded");

    // Do any additional setup after loading the view.
    //  Start listening for events from the beacon manager.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFindMint:) name:@"didLocateMint" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFindBlue:) name:@"didLocateBlue" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFindPurple:) name:@"didLocatePurple" object:nil];

    //Set Up the beacon manager
    dcBeaconManager *beaconManager = [[dcBeaconManager alloc]init];
    [beaconManager initBeaconManager];
}

我正在使用CLLocationServices,但我的应用程序未请求使用位置服务的权限。它出现在列表中,默认情况下处于关闭状态。我已经读过将权限存储在设备上,这可能会解释它,因为我之前测试过这个应用程序,但在新设备上测试会得到相同的结果。

我不会立即使用位置服务,应用程序在决定调用使用位置服务的视图之前会经过一些检查和测量。如果是这样,这就是代码:

-(void)initBeacons {
   dcBeaconManager *beaconManager = [[dcBeaconManager alloc]init]; //Create an instance of the dcBeaconManager class.
    [beaconManager initBeaconManager];  //Start the beacon manager running.
}

调用的类是:

#import "dcBeaconManager.h"

@implementation dcBeaconManager

-(id)init
{
    self = [super init];
    if (self != nil){}
    return self;
}

bool testRanging = true;
bool firstRegionEntered = true;

- (void)initBeaconManager {
    NSLog(@"initBeaconManager called");
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"];
    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"digiConsRegion"];
    [self.locationManager startMonitoringForRegion:self.beaconRegion];
}

- (void)stopBeaconManager {
    [self.locationManager stopMonitoringForRegion:self.beaconRegion];
}

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
    NSLog(@"Started looking for regions");
    [self.locationManager requestStateForRegion:self.beaconRegion];
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"Region discovered");
    if (firstRegionEntered) {
        NSLog(@"First time in region");
        firstRegionEntered = false;
    }
    [self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    NSLog(@"Region left");
    [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.alertBody = @"We hope you enjoyed the event, thank you for coming.";
    notification.soundName = UILocalNotificationDefaultSoundName;
    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
    NSLog(@"locationManager initiated");
    CLBeacon *beacon = [[CLBeacon alloc] init];
    beacon = [beacons lastObject];
    //Store some information about this beacon
    NSNumber *currentBeaconMajor = beacon.major;  //it's major (group) number
    NSNumber *currentBeaconMinor = beacon.minor;  //it's minor (individual) number

    if (([currentBeaconMinor floatValue] == 59204) && ([currentBeaconMajor floatValue] == 33995) && (beacon.proximity == CLProximityNear)) {
        NSLog(@"Mint discovered");
        [[NSNotificationCenter defaultCenter] postNotificationName:@"didLocateMint" object:nil];
    } else if (([currentBeaconMinor floatValue] == 7451) && ([currentBeaconMajor floatValue] == 63627) && (beacon.proximity == CLProximityNear)) {
        NSLog(@"Blue discovered");
        [[NSNotificationCenter defaultCenter] postNotificationName:@"didLocateBlue" object:nil];
    } else if (([currentBeaconMinor floatValue] == 51657) && ([currentBeaconMajor floatValue] == 26976) && (beacon.proximity == CLProximityNear)) {
        NSLog(@"Purple discovered");
        [[NSNotificationCenter defaultCenter] postNotificationName:@"didLocatePurple" object:nil];
    }

}


- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {
    if (testRanging) {
        NSLog(@"Testing: forced ranging");
        if ([region isEqual:self.beaconRegion] && state == CLRegionStateInside) {
            [_locationManager startRangingBeaconsInRegion:(CLBeaconRegion *)region];
        }
    }
}

@end

没有任何委托方法被调用,Malloc最初想知道位置服务,所以我环顾四周,发现了上述特殊错误。

有什么想法?我很高兴分享整个项目。

干杯。

0 个答案:

没有答案