添加新授权过程后MapKit崩溃

时间:2014-09-21 03:17:53

标签: ios mkmapview mapkit ios8 mkuserlocation

我正在尝试让Map Kit将当前用户的位置显示为预定义的大小。

一切正常,但自从更新到Xcode 6和iOS 8后,情况发生了变化。

我已经实施了必要的授权,现在应用程序崩溃了。带***的代码是系统似乎遇到问题的代码。

这是Map.m

#import "MRVCMapViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@import CoreLocation;

@interface MRVCMapViewController ()

@end

@implementation MRVCMapViewController
@synthesize mapView;

- (void)viewDidLoad {
     [super viewDidLoad];

     //location permission

     self.locationManager = [[CLLocationManager alloc] init];
     self.locationManager.delegate = self;


    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
    {
        [self.locationManager requestWhenInUseAuthorization];
    }
    [self.locationManager startUpdatingLocation];

    //mapview settings

    self.mapView.delegate = self;
    self.mapView.showsUserLocation = YES;
}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation   *)userLocation
{
    ***MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate,   800, 800);
     [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];***
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

1 个答案:

答案 0 :(得分:1)

您尚未检查userLocation值是否有效。在尝试将其用于任何事情之前,您应该确保它不是nil