2014-09-21 44 views
0

我正在試圖讓Map Kit將當前用戶的位置顯示爲預定義的大小。添加新的授權過程後MapKit崩潰

一切正常,但自從更新到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 
+0

無論何時說「應用程序崩潰」,都要包含控制檯中顯示的確切崩潰消息。 – Anna 2014-09-22 10:53:07

回答

1

你沒有檢查該userLocation值是有效的。在嘗試將其用於任何事情之前,您應該確保它不是nil

+0

嗨克雷格代碼減去用戶權限更新前工作正常。 – Mark 2014-09-22 21:44:09

+0

您是否嘗試檢查userLocation不是零?也許在它能夠及時獲得位置之前。也許在iOS 8下,獲取位置並首先發出'nil'需要更長的時間。這是很容易檢查,沒有任何更多的細節從你瞭解什麼是崩潰是最好的,我可以建議。 – Craig 2014-09-22 22:10:19