问题
The alerts appear for a split-second or did not show when application launches in project with ARC (without using ARC all it's OK). (I add CoreLocation framework and I import it to project).
My code:
#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; }
回答1:
You are storing the location manager pointer in a local variable. So ARC is free to release that location manager before returning from this method.
If you wish to keep that location manager alive for longer you need to keep a longer term strong reference to it. Like an ivar or property.
来源:https://stackoverflow.com/questions/8384567/disappearing-uilocation-alerts-in-xcode-4-2-with-arc-iphone