views:

741

answers:

3

I'd like to test what happens if my app can't get the location coordinates. Is it possible to disable the location service in the simulator, like on an iPod Touch with WiFI turned off?

I still don't have my iPhone Developer Program certificate, so I can't test it on my device.

Thanks in advance!

A: 

**Disregard this. This works around the MapKit. Check comments below.

Disconnect the computer from internet connection. How to.

EDIT: You can test the code from this site that can be downloaded here

With AirPort on, you get the map. With the AirPort off you get a blank squared view.

erastusnjuki
Sorry if you disconnect internet also it will show the "1 Infinite Loop, Cupertino, USA" location in simulator
Warrior
@Warrior. Check the edit. btw. I have always used this.
erastusnjuki
When using core location framework,and calling [locationManager startUpdatingLocation]; method will give "1 Infinite Loop, Cupertino, USA" location even with Airport off
Warrior
@erastusnjuki MKMapView naturally will not work without internet connection, but CLLocationManager it is not the same. On simulator it will always return same location in cupertino
Vladimir
Aaaaah. Thanks.
erastusnjuki
A: 

To my knowledge, you can't disable the location service on the simulator.

The approach that I normally use when using the location service is to build a simple wrapper class arround NSLocation tailored to the needs of my application.

In this wrapper, you could easily pretend that the service is not working in the simulator. For example, it could have a "isEnabled" method that returns false on the simulator with a compiler define like (#if TARGET_ IPHONE_SIMULATOR)

MLefrancois
A: 

As a workaround you can try to simulate update location failure by constructing NSError object with appropriate values and calling corresponding CLLocationManager delegate didFailWithError: method manually.

Vladimir
Thanks, I'll try this!
Yassin