我有一个带有MapKit View的UIViewController,该应用程序可以在模拟器和连接到我的Mac的物理设备上完美运行,但是当我尝试在断开设备连接的情况下运行该应用程序时,转到MapKit View时会崩溃
我试图使MapKit View成为初始View Controller 我试图重置手机 我试图重置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"
}
}
我希望当物理设备断开连接时,我可以运行该应用程序并查看MapKit视图。
答案 0 :(得分:0)
您需要
import MapKit
在PanicMapViewController
内
答案 1 :(得分:0)
我遇到了同样的问题。即使在输入import MapKit之后。
我做了一些研究,发现设备无法找到当前位置。
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()
}
}
答案 2 :(得分:0)
我遇到了这个问题(用于iOS 12.4的Xcode 11构建),在寻找解决方案时偶然发现了这个问题。
对我来说,我通过在项目文件的“签名和功能”标签下将“地图”添加为“功能”来解决了这个问题。