Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone CLLocation Simulator didUpdateToLocation never called

Tags:

iphone

ios4

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.

like image 752
Taranfx Avatar asked Dec 16 '22 17:12

Taranfx


1 Answers

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!

like image 166
Sudhanshu Avatar answered Dec 19 '22 05:12

Sudhanshu