问题
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!
回答1:
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.
回答2:
You can disable the location services in the simulator;
- Run your app through xcode so the simulator opens
- Stop the app via xcode (this should leave the simulator open)
- Open the Settings app in the simulator window
- Privacy > Location Services. Disable Location Services
- Run your app again, location services should be disabled
Hope it helps!
回答3:
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)
回答4:
**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.
来源:https://stackoverflow.com/questions/2333107/disable-location-service-in-iphone-simulator