【问题标题】:How can it be that both didUpdateToLocation and didFailOnError is not called?怎么会没有调用 didUpdateToLocation 和 didFailOnError 呢?
【发布时间】:2013-04-22 13:56:45
【问题描述】:
+(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

未被调用。它曾经工作过。

【问题讨论】:

    标签: objective-c cllocationmanager


    【解决方案1】:

    您需要使用 performSelectorOnMainThread 设置您的位置管理器。如果在后台线程上设置它将不起作用。很可能是因为您的运行循环在后台线程上不活动。见Why is my CLLocationmanager delegate not getting called?

    【讨论】:

    • 太棒了。如果我有更高的分数,我也会投赞成票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 2015-04-07
    相关资源
    最近更新 更多