iPhone CLLocation Simulator didUpdateToLocation从未调用过

Tar*_*nfx 4 iphone ios4

我知道iPhone模拟器默认为美国某个地方,但这是否意味着didUpdateToLocation永远不会被调用?所有被调用的都是didFailWithError,经过很长一段时间.调用此方法的超时时间是多少?

ps Android在这方面要好得多,让你假冒位置.

Sud*_*shu 6

是的如果你正在使用iPhone simulator那么这didUpdateToLocation将永远不会调用,因为在模拟器的情况下不可能进行位置更新,我在我的一个应用程序中面临相同的情况(模拟器测试变得困难),所以我定制了经度和纬度以防万一didFailWithError方法本身的模拟器.如下所示

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError*)error{
if( [(NSString *)[[UIDevice currentDevice] model] isEqualToString:@"iPhone Simulator"] ){

        lat = 50.748129f;
        log = -2.970836f;

        return;
    }
[[LocationManager sharedManager].locationManager stopUpdatingLocation];
    [LocationManager sharedManager].isUpdating = NO;
}
Run Code Online (Sandbox Code Playgroud)

现在,您可以使用此位置测试您的应用,就像设备搜索当前位置时一样.

希望你有我想说的话

祝好运!