开发者

iphone simulator crashes when it tries to access user location

开发者 https://www.devze.com 2023-01-04 02:08 出处:网络
for some reason my code causes my program to crash. does anyone know why or how to fix it? NSLog(@\"here\");

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);

0

精彩评论

暂无评论...
验证码 换一张
取 消