1

I have a UIViewController with a MapKit View inside of it, the app runs perfectly in simulator and physical device connected to my mac, but when I try to run the app with the device disconnected, it crashes when going to the MapKit View

I Tried to make the MapKit View the initial View Controller I tried to reset my phone I tried to reset Xcode

import UIKit
import ChameleonFramework
class PanicMapViewController: UIViewController {

    override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = FlatYellowDark()
    configureNavigationBar()
}

func configureNavigationBar() {
    navigationController?.navigationBar.barTintColor = FlatYellowDark()
    navigationController?.navigationBar.barStyle = .black
    navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:ContrastColorOf(FlatYellowDark(),returnFlat: true)]
    navigationItem.title = "Side Menu"

}

}

I expect that when my physical device is disconnected I can run the app and see the MapKit view.

  • Hi Andres welcome to SO! While I can't directly see what's causing the crash from the code you provided. It'd help us out to see what the crash log said. Also, you can see (usually) where its crashing by using a exception breakpoint in xcode. I hope that helps some! – Chris J May 20 '19 at 17:15
  • make sure MKMap view find your current location if it s not its crash. see this link-https://stackoverflow.com/a/46399655/8687925 – SAXENA May 20 '19 at 17:53
  • Thats what is weir, it doesn´t throw a crash log, looks like everything is runnign correctly. – Andres De La Ossa May 20 '19 at 17:58

3 Answers3

1

I was having this problem (Xcode 11 building for iOS 12.4) and stumbled across this question whilst looking for a solution.

For me, I resolved the problem by adding 'Maps' as a 'Capability' under the 'Signing and Capabilities' tab of the project file.

Andy P
  • 667
  • 7
  • 14
0

You need to

import MapKit

Inside PanicMapViewController

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

I was having same issue. even after typing import MapKit.

i did some research and found out the device was not able to find current location.

import UIKit
import MapKit


Class PSSearchVC: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate  {

@IBOutlet var mapview: MKMapView!

let locationmanager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()

     mapview.mapType = MKMapType.standard

    let location = CLLocationCoordinate2DMake(22.4651, 70.0771)

    let span = MKCoordinateSpan.init(latitudeDelta: 0.01, longitudeDelta:
    0.01)
    let coordinate = CLLocationCoordinate2D.init(latitude: 21.282778, longitude: -157.829444) // provide you lat and long
    let region = MKCoordinateRegion.init(center: coordinate, span: span)
    mapview.setRegion(region, animated: true)

    let annonation = MKPointAnnotation()
    annonation.coordinate = location
    annonation.title = "Chandi Bazar"
    annonation.subtitle = "Jamnagar"
    //
    mapview.addAnnotation(annonation)

    self.locationmanager.requestWhenInUseAuthorization()

    if CLLocationManager.locationServicesEnabled()
    {
        locationmanager.delegate = self
        locationmanager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        locationmanager.startUpdatingLocation()
    }


}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    let locValue:CLLocationCoordinate2D = manager.location!.coordinate
    print("locations = \(locValue.latitude) \(locValue.longitude)")

    locationmanager.stopUpdatingLocation()
}

}