In xcode 9 with iOS 11 - issue with loading of Map tiles on first run

爷,独闯天下 提交于 2019-12-04 18:14:46

问题


--Updated with new findings -- Tested in both simulator and on device. Maps are not loaded correctly when the app is run from a cold start. Tiles are not being displayed.

mapViewDidFinishLoadingMap is not being called. So something is going wrong for the map not to finish, but I am getting no errors.

The map is loaded fine if I just briefly go out of the app and then in again. Meaning that the maps are loaded if app is opened from background.

Any ideas what has change? Worked just fine in iOS 10.

Update

In iOS 11 mapViewWillStartLocatingUser is being called but not mapViewWillStartRenderingMap. I wondering if I have to manual call something so that the rendering off the map will be started. In iOS 9 (what I test against, and were it works just fine) mapViewWillStartRenderingMap is called before mapViewWillStartLocatingUser


回答1:


I Think you should try By removing

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

}

and Putting following code into your View Didload Method

    CGFloat edge = 10.0f;

    UIImage *gotoUserLocationButtonImage = self.gotoUserLocationButton.imageView.image;
    self.gotoUserLocationButton.frame = CGRectMake(edge, edge + self.statusBarHeight, gotoUserLocationButtonImage.size.width, gotoUserLocationButtonImage.size.height);

    UIImage *getDirectionsButtonImage = self.getDirectionsButton.imageView.image;
    [self.getDirectionsButton setFrame:CGRectMake(CGRectGetMaxX(self.gotoUserLocationButton.frame), edge + self.statusBarHeight, getDirectionsButtonImage.size.width, getDirectionsButtonImage.size.height)];



回答2:


Make sure you are not using dispatch_async for the map.

I had the following function that did not work in iOS11

dispatch_async(dispatch_get_main_queue(), ^{
    @synchronized(_queue) {
        if(poppedMapView != nil) {
            [self.queue removeObject:poppedMapView];
        }
        [self.queue addObject:[[MKMapView alloc] init]];
    }
});

Changed it to

if(poppedMapView != nil) {
    [self.queue removeObject:poppedMapView];
}
[self.queue addObject:[[MKMapView alloc] init]];



回答3:


I had exactly same problem, spent a lot of time to find a solution and finally I did. So in my case problem was with wrong inisializing. Usually you would write let mapView = MKMapView() on the top of the viewController and then customise it somewhere later inside viewDidLoad but after IOS 11 Beta 1 it stopped working. I fixed it by changing to var mapView: MKMapView? on the top of the viewController and then inside viewDidLoad I inisializ it like mapView = MKMapView(). Hope it helps someone! :)




回答4:


Had same problem my BROKEN code looked something like:

class ViewController: UIViewController {

    fileprivate var mapView = MKMapView()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Add the mapView to the VC
        mapView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(mapView)
        mapView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        mapView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
        mapView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    }
}

As it turned out in iOS 11 it does not like having the MKMapView initialize before the view controller has loaded ie viewDidLoad() so FIX was changing to:

class ViewController: UIViewController {

    fileprivate var mapView: CSMapView?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Init instance here.
        mapView = CSMapView()

        // Add the mapView to the VC
        mapView?.translatesAutoresizingMaskIntoConstraints = false
        ...
    }
}

Also tried putting it in init methods but this DID NOT work for me:

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    mapView = MKMapView()
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    mapView = MKMapView()
}


来源:https://stackoverflow.com/questions/46049985/in-xcode-9-with-ios-11-issue-with-loading-of-map-tiles-on-first-run

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!