当前位置警报和点未显示在iOS8中
从iOS7移动到iOS8,我的应用程序不会显示当前位置的警报或蓝点。我试图根据我在这里读到的内容更改代码,现在警报正在显示,但只有一瞬间,没有机会选择任何内容。不用说,蓝点也不存在。 我的代码是: MapName.h MapName.m 我已将NSLOCATIONWHENISUSAGESCRIPTION字符串和我在警报中看到的消息添加到Info.plist中。问题已解决: MapName.h 首先将密钥nsLocationWhenUsageDescription作为字符串添加到Info.plist当前位置警报和点未显示在iOS8中,ios8,alert,core-location,cllocationmanager,xcode6,Ios8,Alert,Core Location,Cllocationmanager,Xcode6,从iOS7移动到iOS8,我的应用程序不会显示当前位置的警报或蓝点。我试图根据我在这里读到的内容更改代码,现在警报正在显示,但只有一瞬间,没有机会选择任何内容。不用说,蓝点也不存在。 我的代码是: MapName.h MapName.m 我已将NSLOCATIONWHENISUSAGESCRIPTION字符串和我在警报中看到的消息添加到Info.plist中。问题已解决: MapName.h 首先将密钥nsLocationWhenUsageDescription作为字符串添加到Info.plis
#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
//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];
#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
- (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;
}