地图应用程序在加载到不同的设备模拟器时崩溃

时间:2016-05-06 17:58:38

标签: ios swift firebase maps geofire

我正在开发一个应用,其中主屏幕是带注释的地图。注释坐标使用GeoFire存储在Firebase数据库中。

我在iPhone 6和Xcode的Iphone 6模拟器上完成了所有测试,一切运行正常,我能够在地图上添加注释,并保存/检索我的Firebase。

添加了我的自动布局约束后,我想在不同大小的设备上测试应用程序,即iPhone 5S。 模拟器启动后,我立即让应用程序崩溃并显示错误消息:

import UIKit
import MapKit
import GeoFire
import Firebase

class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var honkButton: UIButton!

var locationManager = CLLocationManager()
var startedTrackingUser = false
var regionQuery = GFRegionQuery();

@IBAction func logOutButton(sender: AnyObject) {
    ref.unauth()
}

override func viewDidLoad() {
    super.viewDidLoad()
    mapView.delegate = self
    honkButton.enabled = false
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestWhenInUseAuthorization()
    locationManager.startUpdatingLocation()

    mapView.showsUserLocation = true
}

override func viewWillDisappear(animated: Bool) {
    regionQuery.removeAllObservers()
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if startedTrackingUser == false {
        let userLocation:CLLocation = locations[0]
        let latitude = userLocation.coordinate.latitude
        let longitude = userLocation.coordinate.longitude
        let latDelta:CLLocationDegrees = 0.05
        let longDelta:CLLocationDegrees = 0.05
        let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
        let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
        let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
        self.mapView.setRegion(region, animated: false)

        updateQuery()
        startedTrackingUser = true
    }
}

func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
    let annotations = self.mapView.annotations.filter { $0 !== mapView.userLocation } // Get all annotations on the map
    mapView.removeAnnotations(annotations)
    updateQuery()
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "addSpotSegue" {
        let vc = segue.destinationViewController as! AddViewController
        vc.userLocation = mapView.userLocation.location!
    }
}

func updateQuery() {
    // query data
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
    if !(annotation is SpotAnnotation) {
        return nil
    }

    let reuseId = "test"

    var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
    if anView == nil {
        anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        anView!.canShowCallout = true
    }
    else {
        anView!.annotation = annotation
    }

    //Set annotation-specific properties **AFTER**
    //the view is dequeued or created...

    let cpa = annotation as! SpotAnnotation
    anView!.image = UIImage(named:cpa.imageName)

    return anView
}

我的Firebase数据库中没有这样的坐标记录,我决定放弃数据库中的所有内容,应用程序开始在所有设备上运行,这对我来说是一个谜......

我还发现,当我在测试iPhone 6上快速缩小时,应用程序崩溃时出现同样的错误......

如果有人对此有任何线索,那将会有很大的帮助......这是我VC的快照

{{1}}

}

0 个答案:

没有答案