【发布时间】:2014-09-15 12:26:15
【问题描述】:
我一直在尝试使用 MKMapview 移动我的 iOS7 应用程序以支持 iOS8。但是,我无法获得要求用户共享其位置以正常工作的新请求。我在情节提要上创建了我的 MKMapView,并且委托已设置并在 iOS7 上完美运行。这是我为支持 iOS8 位置共享而添加的内容:
myMapView.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface myMapView : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
@property (strong, nonatomic) CLLocationManager *locationManager;
myMapView.m
//Code omitted
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
//Code omitted
- (void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if(IS_OS_8_OR_LATER) {
//[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization];
[self.locationManager startUpdatingLocation];
}
[self.mapView setShowsUserLocation:YES];
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = self.locationManager.location.coordinate.latitude;
region.center.longitude = self.locationManager.location.coordinate.longitude;
region.span.latitudeDelta = 0.0187f;
region.span.longitudeDelta = 0.0137f;
[self.mapView setRegion:region animated:YES];
_initialPosition = NO;
}
我还在 InfoPlist 中设置了 NSLocationAlwaysUsageDescription 键及其值,当提示用户分享他们的位置时,它会显示正确的消息。
不幸的是,委托函数-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 永远不会被调用。虽然每次加载 viewController 时都会调用 [self.locationManager startUpdatingLocation],但委托似乎没有响应它。我如何设置委托是否有问题,或者我在这里还缺少什么?
更新: 似乎我的 gpx 文件在启动时也没有被调用。我已经清除并重新加载了我的位置文件,甚至更改为默认位置,但没有找到位置:Domain=kCLErrorDomain Code=0
更新 2: 这是我实际成功处理用户请求的设置中的 SS,但无论我刷新多少次都无法获取/更新位置。
(来源:barisaltop.com)
谢谢!
【问题讨论】:
-
我也有同样的问题。你找到解决这个问题的方法了吗?
标签: ios objective-c mkmapview ios8 cllocationmanager