在我的 AppDelegate 我有一个属性:
GPSTracking* _GPSTracker;
负责启动位置更新。它使用单例CLLocationManagerDelegate
并像这样使用它:
@implementation GPSTracking
-(id) initWithDelegate:(MSpyAppDelegate *) _del
{
if (self = [super init])
{
self.mainDelegate = _del;
[[InternalGPSManager sharedInstance] setMainDelegate: self.mainDelegate];
}
return self;
}
//Start getting locations
- (void)startUpdatingByManager
{
[[InternalGPSManager sharedInstance] startLocationUpdateInSeparateThread];
self.gpsTimer = [NSTimer scheduledTimerWithTimeInterval:(gpsUpdateInterval * 60) target:self selector:@selector(startUpdatingByManager) userInfo:nil repeats:NO]
}
实际位置经理委托:
内部GPSManager.h:
@interface InternalGPSManager : NSObject <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
内部GPSManager.m
static InternalGPSManager *sharedCLDelegate = nil;
@implementation InternalGPSManager
@synthesize locationManager;
- (id)init
{
self = [super init];
if (self != nil)
{
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
return self;
}
- (void)startLocationUpdateInSeparateThread
{
[NSThread detachNewThreadSelector:@selector(startLocationUpdate) toTarget:self withObject:nil];
}
- (void)startLocationUpdate
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self.locationManager startUpdatingLocation];
[pool release];
}
它适用于 iOS 4,但不适用于 iOS 5。位置委托回调永远不会被调用。有任何想法吗?