Ios 位置服务未请求许可
我有件奇怪的事 修复:我在viewDidLoad方法中创建了我的CLLocationManager,因此ARC几乎立即对其进行了清理。我将实例改为类实例而不是方法实例,问题就解决了。Ios 位置服务未请求许可,ios,core-location,ibeacon,Ios,Core Location,Ibeacon,我有件奇怪的事 修复:我在viewDidLoad方法中创建了我的CLLocationManager,因此ARC几乎立即对其进行了清理。我将实例改为类实例而不是方法实例,问题就解决了。 - (void)viewDidLoad { [super viewDidLoad]; //Grab the JSON from dcJSONParser NSURL *mainContentURL = [NSURL URLWithString:@"http://www.andrewl
- (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];
}
更新:调用位置服务的视图直接显示在下面。允许位置服务的请求弹出,然后立即消失。
- (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最初想知道位置服务,所以我环顾四周,发现了上面的特殊错误
有什么想法吗?我很高兴分享整个项目
干杯。您的应用程序是否列在隐私设置的“位置服务”下?默认情况下是关闭的。如果该应用程序列在隐私设置中,则用户已被询问。每个应用程序只会请求一次权限,除非您重置所有隐私设置。这是令人困惑的事情,重置隐私设置,重新运行应用程序,没有任何区别。您得到解决方案了吗?我也有类似的问题。在我的情况下,首次使用CLLocationManager不会触发授权请求:let authorizationStatus=CLLocationManager.authorizationStatus()