从iOS7移动到iOS8,我的应用程序没有显示当前位置的警报或蓝点。我试图根据我在这里阅读的内容更改我的代码,现在警报显示但仅仅是一瞬间,没有机会选择任何东西。毋庸置疑,蓝点也不存在。 我的代码是:
MapName.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface MapName : UIViewController <MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *MapName;
@property (nonatomic, retain) CLRegion *region;
@property (nonatomic) BOOL showsUserLocation;
@end
MapName.m
//in the (void)viewDiDLoad section
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = _MapName; //Assigning to 'id<CLLocationManagerDelegate>' from incompatible type 'MKMapView*_strong' warning showing here
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusDenied ||
status == kCLAuthorizationStatusAuthorizedWhenInUse) {
//UIApplication -openUrl: UIApplicationOpenSettingsURLString //this is the example shown on WWDC
}
[locationManager requestWhenInUseAuthorization];
[locationManager startMonitoringForRegion:_region];
我已将NSLocationWhenIsUseUsageDescription字符串添加到Info.plist中的消息(我在警报中看到)
答案 0 :(得分:0)
问题解决了:
<强> MapName.h 强>
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface MapName : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *MapName;
@property (strong, nonatomic) CLLocationManager *locationManager;
@end
<强> MapName.m 强>
- (void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
//Center the map
[self gotoLocation];
//Show current position
_MapName.showsUserLocation = YES;
}
首先将密钥NSLocationWhenInUseUsageDescription作为字符串添加到Info.plist中