iphone simulator crashes when it tries to access user location
for some reason my code causes my program to crash. does anyone know why or how to fix it?
NSLog(@"here");
CLLocation *location = [locationManager location];
[mapView r开发者_如何学编程emoveAnnotations:mapView.annotations];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
CLLocationCoordinate2D workingCoordinate = [location coordinate];
NSLog(@" this is %@", workingCoordinate.latitude);
it makes it to the first NSLog, but somewhere between the first and second it crashes. My guess is that it has to do with the CLLocation *location line.
CLLocationCoordinate2D
is a struct containing two non-object fields of type CLLocationDegrees
. The %@
passed to the NSLog
will try to interpret the value as an object reference and that is causing the crash.
Try: NSLog(@" this is %d", workingCoordinate.latitude);
精彩评论