IPhone CLLocation Simulator didUpdateToLocation never called

I know that the default iPhone simulator takes place in the USA, but does this mean that didUpdateToLocation will never be called? All that is called is didFailWithError , this is also after a long time. What is the timeout for calling this method?

ps Android is much better at this, allowing you to fake a location.

+4
source share
5 answers

Yes, if you are using an iPhone simulator , then this didUpdateToLocation will never be called, because location updates are not possible in the case of a simulator, I faced the same situation in one of my applications (testing the simulator becomes difficult) so I set the longitude and latitude in the case of the simulator in the didFailWithError method didFailWithError . As 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 application with this location in the same way as with the device when searching for the current location.

I hope you have what I want to say

Good luck

+6
source

You can also get didUpdateToLocation updates also in the simulator.

  • However, you need to include the code in a thread with an active run loop, such as your main application thread. This has the advantage that GPS has time to update while the user clicks on your APP. :)
  • Configure the simulator (checked on 5.1) You can configure the simulator (Debug> Location), for example. with own location. To do this, go to GoogleMaps. Tip: close the simulator to apply the latest changes!

I added this to the viewDidLoad of the main loop:

  self.locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager startUpdatingLocation]; 

And the trick 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.

+3
source

You do not receive location updates on the iphone simulator.

+1
source

iOS 5 now takes place as a mutable parameter in the simulator. In the simulator, select the menu Debug → Location and select one of the static or dynamic location routes.

The Xcode debugger also allows you to change the location - find the small space arrow next to the play / pause / step buttons to change the location on the right in Xcode.

+1
source

I found a strange error with didUpdateLocations that is not being called on the simulator. If you use a custom location (like me), after starting a new instance of the simulator, iOS won't return the user location until you do:

Select "Apple" as your location: Debug → Location → Apple

Then go back to your custom location: Debug → Location → Custom Location

+1
source

Source: https://habr.com/ru/post/1340745/


All Articles