I have a pretty basic app configured. It uses a navigation controller, along with a view controller that i have configured as my map view controller.
When the app launches, it launches to the Root View Controller, and from there, i have a button that's configured to segue to the map view controller and display the map. When this happens, the alert view will display, but before i can select allow/don't allow, it disappears and the map loads.
Why does the alert view disappear on its own?
I've configured the info.plist file accordingly, added the necessary frameworks and added the appropriate delegates.
Below is the code i have configured:
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation = locations[0]
let latitude = userLocation.coordinate.latitude
let longitude = userLocation.coordinate.longitude
let latDelta: CLLocationDegrees = 0.01
let lonDelta: CLLocationDegrees = 0.01
let coordinate: CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
let span: MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
let region: MKCoordinateRegion = MKCoordinateRegionMake(coordinate, span)
map.setRegion(region, animated: true)
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print(error)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Any help will be greatly appreciated! Thanks in advance!