- Run the app from Xcode.
- In the debug bar, click the "Simulate location" button.
- Choose a location from the menu.
Add own custom location using GPX file
To check for location services we need real device but for testing purpose we can also use simulator and add our own location by following below steps:
- add new GPX file into your project.
- in GPX file add waypoints like
- then go to product-->Scheme-->Edit Scheme and into RUN set default location as your GPX file name.
Link CoreLocation Framework
Import the CoreLocation module in your classes that use CoreLocation functionality.
Location Services in the Background
To use standard location services while the application is in the background you need first turn on
Background Modes in the Capabilities tab of the Target settings, and select
Or, add it directly to the Info.plist.
Then you need to setup the CLLocationManager
Request Permission to Use Location Services
Check the app's authorization status with:
Test the status against the follow constants:
Getting Location Service Permission While App is in Use
Simplest method is to initialize the location manager as a property of your root view controller and place the permission request in its
This brings up the alert controller that asks for permission:
Add the NSLocationWhenInUseUsageDescription key to your Info.plist. The value will be used in the alert controller's
Getting Location Service Permission Always
To ask for permission to use location services even when the app is not active, use the following call instead:
Then add the NSLocationAlwaysUsageDescription key to your Info.plist. Again, the value will be used in the alert controller's
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0