警报显示为瞬间,或者在使用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; }
答案 0 :(得分:7)
您正在将位置管理器指针存储在本地变量中。因此,ARC可以在从此方法返回之前释放该位置管理器。
如果您希望让位置管理员保持更长时间,您需要长期保持对它的强烈参考。像伊娃或财产。