Managing Location Services
The location of a user’s device is sensitive information, and that’s why our app needs to get permission from users to access it. In this section, we’ll create a class that manages the access to and handling of the location data.
In Xcode, create a new file using the shortcut ⌘N, select the Cocoa Touch Class template, and click Next. Type LocationProvider in the Class text field and make it a subclass of NSObject. Click Next and then click Create.
Asking for Permission
Our app will access the location services via an instance of CLLocationManager, which is defined in CoreLocation. Import CoreLocation below the existing import statement:
| import UIKit |
| import ... |
Get Build Location-Based Projects for iOS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.