Reputation: 10447
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.
Upvotes: 4
Views: 3929
Reputation: 2077
I found a weird bug with the didUpdateLocations not being called on the simulator. If you're using a custom location (like I am), after starting a fresh instance of the simulator, iOS fails to return back the custom location until you do:
Select "Apple" as your location: Debug -> Location -> Apple
Then switch back to your custom location: Debug -> Location -> Custom Location
Upvotes: 1
Reputation: 4409
You can get didUpdateToLocation updates also in the simulator.
I have added this in the viewDidLoad of main loop:
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
And the catch of the result:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
// Display location in Log
NSLog(@"Lat= %s Lon=%f", newLocation.coordinate.latitude,
newLocation.coordinate.longitude);
// Stop updating, when one is enough
[locationManager stopUpdatingLocation];
}
Hope this helps.
Upvotes: 3
Reputation: 959
iOS 5 now has location as a modifiable parameter in the simulator. In the Simulator, select the menu Debug -> Location, and choose one of the static or dynamic location routes.
The Xcode debugger also allows you to change the location - look for the little location arrow beside the play/pause/step buttons to change the location from right within Xcode.
Upvotes: 1
Reputation: 3960
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!
Upvotes: 6