0
+(void) vStartUpdatingLocation
{
    while (false);
    AssertNonMainThread
    [[NSOperationQueue mainQueue]addOperationWithBlock:^{
        CLLocationHandler * singleton = [CLLocationHandler singleton];
        CLLocationManager * locationManager = singleton.locationManager;
        NSAssert(locationManager.delegate==singleton,@"They are meant for each other"); //Assertion here
        [locationManager startUpdatingLocation]; //update location
        PO(singleton.locationManager);
        PO(singleton.locationManager.delegate);
        PO(singleton); //verify that locationManager.delegate == singleton
        while(false);
    }];
}
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    AssertMainThread;//break point here never called
    PO(self.locationManager);
    PO(manager);
    while(false);
    [self finishUpdating];
    [self updateCurrentPlaceCache:newLocation];
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    [self finishUpdating]; //no love here too
}

我把大部分信息放在评论上。

我已经验证 locationManager.delegate 确实是 CLLocationHandler 类型的单例对象

然而

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

不叫。它曾经工作过。

4

1 回答 1

0

您需要使用 performSelectorOnMainThread 设置您的位置管理器。如果在后台线程上设置它将不起作用。很可能是因为您的运行循环在后台线程上不活动。请参阅为什么我的 CLLocationmanager 委托没有被调用?

于 2013-04-22T14:35:35.270 回答