问题
I use google maps iOS SDK with storyboard. Application starting with Navigation View Controller that has a Root View Controller with map.
@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];
}
Button btnMyLock push the Table View Controller. In iOS 7 it's ok. But iOS 6 my app crashes. Sometimes crash with EXC_BAD_ACCESS (code=1) or code=2
回答1:
Problem that I used Autolayout view.
回答2:
you forgot step 4: "Drag the GoogleMaps.bundle" from the Resources folder to your project.
I suggest putting it in the Frameworks group. When prompted, ensure "Copy items into destination group’s folder" is not selected. i encountered the same problem, and this fixed it.
回答3:
I don't know if it's causing the problem, but I wouldn't do:
self.view = mapView_;
Just add the mapView_
as a subview, like:
[self.view addSubview:mapView_];
In general EXC_BAD_ACCESS crashes are caused when you are mismanaging memory (e.g. an object is being deallocated prematurely). Try to find out what object the crash is happening on.
Create your buttons in code, not from the xib as IBOutlets. Otherwise they are not loaded since you are not using the xib.
回答4:
Use this code when you use Google map and then check its not crash when you navigate to another screen.
- (void)dealloc {
[super dealloc];
[mapView_ removeObserver:self
forKeyPath:@"myLocation"
context:NULL];
}
来源:https://stackoverflow.com/questions/19584955/google-maps-ios-sdk-crash