位置服务权限警报消失得太快

时间:2015-02-11 03:11:23

标签: ios xcode cllocationmanager class-variables

我遇到与此处发布的问题相同的问题: Current location permission dialog disappears too quickly

我尝试了第一个似乎适用于其他人的答案,但我收到了EXC_BAD_ACCESS错误。我认为我没有正确使用类级实例变量。

标题文件

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

@interface whatever : NSObject     <NSURLConnectionDataDelegate, CLLocationManagerDelegate>

+ (CLLocationManager *)locationManager;

@end

实施文件

//#import header file
@interface whatever()

@property CLLocationManager *locationManager;

+ (CLLocationManager *)locationManager;

@end

@implementation whatever

+ (CLLocationManager *)locationManager;
{
    static CLLocationManager *locationM = nil;
    if(locationM == nil)
    {
        locationM = [[CLLocationManager alloc] init];
    }
    return locationM;
}

- (id)init
{
    if(self = [super init])
    {
        self.locationManager = [whatever locationManager];
        self.locationManager.delegate = self;
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;     
    }
     return self;
}
- (void)myMethod
{
    if([CLLocationManager locationServicesEnabled])
    {
        [self.locationManager startUpdatingLocation];
    }
}

0 个答案:

没有答案