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

标签 iphone ios

在我的 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/

相关文章:

iphone - AFNetworking -- 获取重定向 URL

iphone - 通过分段控件在标准样式表和分组样式表之间翻转

iPhone/iPad 旋转

ios - 具有一个 UDID 的 ADHoc Distribution Provisioning 配置文件在两台设备上工作

ios - Firebase crashlytics 报告我的生产版本中存在许多 <编译器生成的> 第 0 行崩溃,这些崩溃是真的吗?

iphone - 对具有许多对象的核心数据进行单元测试

iphone - UIScrollView如何自动包裹内容?

ios - 如何集成AdMob作为iAds的备份?

ios - 我需要 UIView 上的 UITableView 帮助( Storyboard项目)

ios - Xcode 错误 "Profile doesn' t include the beta-reports-active entitlement"for adhoc profile