使用ARC iPhone在XCode 4.2中消失UILocation警报

Sla*_*uta 4 iphone uialertview

警报显示为瞬间,或者在使用ARC的项目中启动应用程序时未显示(不使用ARC,一切正常).(我添加CoreLocation框架并将其导入项目).

我的代码:

#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; }
Run Code Online (Sandbox Code Playgroud)

Fir*_*eer 7

您将位置管理器指针存储在本地变量中.因此,ARC可以在从此方法返回之前释放该位置管理器.

如果您希望让位置管理员保持更长时间,您需要对其进行长期强有力的参考.像伊娃或财产.