Disappearing UILocation alerts in Xcode 4.2 using iPhone ARC

Alerts appear for a second or do not appear when an application is launched in a project with ARC (without using ARC, everything is in order). (I add the CoreLocation structure and import it into the project).

My code is:

#import <CoreLocation/CoreLocation.h> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ CLLocationCoordinate2D coordinate; CLLocationManager *locationManager = [[CLLocationManager alloc] init]; NSLog(@"jestem po okienku "); if (locationManager.locationServicesEnabled == NO) { coordinate.latitude = 0.0; coordinate.longitude = 0.0; } else { locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager startUpdatingLocation]; CLLocation *location = [locationManager location]; if (!location) { coordinate.latitude = 0.0; coordinate.longitude = 0.0; } // Configure the new event with information from the location. coordinate = [location coordinate]; } return YES; } 
+4
source share
1 answer

You store the location manager pointer in a local variable. Therefore, ARC may release this location manager before returning from this method.

If you want to keep this location manager longer, you need to keep a long-term link to it. Like ivar or property.

+7
source

Source: https://habr.com/ru/post/1384677/


All Articles