使用ARC iPhone在XCode 4.2中消失UILocation警报 [英] Disappearing UILocation alerts in XCode 4.2 with ARC iPhone

查看:118
本文介绍了使用ARC iPhone在XCode 4.2中消失UILocation警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我的代码:

#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; }


推荐答案

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

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.

这篇关于使用ARC iPhone在XCode 4.2中消失UILocation警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆