我试图在iOS 8中使用重要的更改位置监视,但从未调用didUpdateLocations方法。下面是设置位置管理器的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager requestWhenInUseAuthorization];
[locationManager startMonitoringSignificantLocationChanges];
}尽管调用了requestWhenInUseAuthorization,但没有任何东西弹出要求用户授权它。我已经设置了NSLocationWhenInUseUsageDescription,但它仍然不能工作。didChangeAuthorizationStatus和didFailWithError也从未被调用过。编辑:我可以让它要求用户允许位置服务,但即使您单击“允许”,它也不会显示位置。
发布于 2014-08-13 10:19:46
目前,iOS8 beta5中有一个bug,它总是禁用应用程序的地理定位服务(至少对于我的应用程序是这样)。
进入settings > Privacy > Location services > Your app > Always。
但是我不知道为什么,但是即使你把它设置为Always,这个设置也会自动停用,所以请耐心并且经常在设置中返回来重新配置您的应用程序位置。
发布于 2014-07-21 23:37:25
尝试在头文件中声明CLLocationManager *locationManager,然后它就能工作了。除非我声明它为全局变量,否则它不会请求权限和更新位置。
.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}.m
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:(id)self];
[locationManager requestWhenInUseAuthorization];
[locationManager startMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];
}委托方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(@"Getting Location");
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"%@", error.localizedDescription);
}info.plis

发布于 2014-10-20 14:36:14
到.plist文件中添加

locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
if(IS_OS_8_OR_LATER)
{
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
}
}
[locationManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
currentLocation = [locations lastObject];
}https://stackoverflow.com/questions/24874997
复制相似问题