Google Maps iOS SDK崩溃

我使用谷歌地图iOS SDK与故事板。 从具有根视图控制器和导图的导航视图控制器开始的应用程序。

@implementation MyViewController @synthesize btnMyLock; @synthesize btnNearby; GMSMapView *mapView_; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:20 longitude:20 zoom:0]; mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView_.myLocationEnabled = YES; self.view = mapView_; // Creates a marker in the center of the map. GMSMarker *marker = [[GMSMarker alloc] init]; [marker setIcon:[UIImage imageNamed:@"pin"]]; marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); marker.title = @"Sydney"; marker.snippet = @"Australia"; marker.map = mapView_; mapView_.settings.compassButton = YES; [mapView_ addSubview:btnMyLock]; [mapView_ addSubview:btnNearby]; } 

buttonbtnMyLock推动表视图控制器。 在iOS 7中没关系。 但iOS 6我的应用程序崩溃。 有时会因EXC_BAD_ACCESS(代码= 1)或代码= 2而崩溃

我使用Autolayout视图的问题。

您忘记了第4步:从“资源”文件夹中拖动“GoogleMaps.bundle ”到您的项目中。

我build议把它放在框架组。 出现提示时,请确保没有select“将项目复制到目标组的文件夹”。 我遇到了同样的问题,并修复了这个问题。

我不知道是否是造成这个问题,但我不会这样做:

 self.view = mapView_; 

只需将mapView_添加为子视图,如:

 [self.view addSubview:mapView_]; 

一般情况下,EXC_BAD_ACCESS崩溃是在内存pipe理不当时引起的(例如,一个对象被提前解除分配)。 试着找出崩溃正在发生的对象。


在代码中创buildbutton,而不是从IBO作为IBOutlets。 否则,他们不会被加载,因为你没有使用xib。

当您使用Google地图时使用此代码,然后在导航到另一个屏幕时检查其没有崩溃。

 - (void)dealloc { [super dealloc]; [mapView_ removeObserver:self forKeyPath:@"myLocation" context:NULL]; }