gpt4 book ai didi

iphone - GPS 在 iOS 4 上工作但在 iOS 5 上不工作

转载 作者:行者123 更新时间:2023-11-29 11:10:52 25 4
gpt4 key购买 nike

在我的 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]
}

实际位置经理委托(delegate):

内部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。永远不会调用位置委托(delegate)回调。有什么想法吗?

最佳答案

幽默一下,然后尝试将您的代码更改为:

- (void)startLocationUpdateInSeparateThread
{
// Not a separate thread!
NSLog(@"Starting updates using delegate: %@", self.locationManager.delegate);
[self.locationManager startUpdatingLocation];
}

PS:你为什么不用ARC???

关于iphone - GPS 在 iOS 4 上工作但在 iOS 5 上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11635094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com