CLLocationManager tutorial and troubleshooting

Many developers complain Mobile application development is more difficult than web application development. They try to follow tutorials online precisely but the mobile application still doesn’t work. This is because mobile platforms evolve rapidly and tutorials just can’t keep up-to-date.

My friend had the above situation and failed to get any location update from the location manager. He added CoreLocation.framework library to Link Binary,

CLLocationSample1

CLLocationSample2

Then, he put below code and sounds right.

However, nothing comes out to the console. This is because starting from add NSLocationAlwaysUsageDescription orNSLocationWhenInUseUsageDescription starting from iOS 8, depending on requestAlwaysAuthorization (for background location) or requestWhenInUseAuthorization (location only when foreground).

CLLocationSample3

CLLocationSample4

Let’s start to build and run the App. You should see below alert if you start it the first time.

CLLocaationManager5

You should get an update after tapped Allow. You many need to adjust location if you are running Simulator by choosing a location from Debug -> Location.

I have upload the project to https://github.com/neoalienson/CLLoacationManagerSample

Good luck and hope this tutorial is not outdated very soon!

 

Share