Disappearing UILocation alerts in XCode 4.2 with ARC iPhone

China☆狼群 提交于 2019-12-01 05:16:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!