Search code examples
iphoneios4

iPhone CLLocation Simulator didUpdateToLocation never called


I know iPhone simulator is defaulted to a location in US, but does that mean that didUpdateToLocation will never be called? All that gets called is didFailWithError, that too after a long time. What is the timeout for this method to be called?

p.s. Android is much better at this, lets you fake location.


Solution

  • Yes in case if you are using iPhone simulator then this didUpdateToLocation will never called because location updates are not possible in case of simulator,i was facing the same situation in one of my application(simulator testing become difficult),so i customized the longitude and latitude in case of simulator in the didFailWithError method itself.Like below

    - (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;
    }
    

    Now you can test your app with this location likewise you do in case of device when your current location is searched.

    Hope you got what i want to say

    Good Luck!