在使用iOS 11的Xcode 9中,首次运行时地图瓦片加载出现问题。

13

--更新了最新的发现--在模拟器和实际设备上测试。当应用程序从冷启动运行时,地图没有正确加载,瓦片也没有显示。

mapViewDidFinishLoadingMap 没有被调用。所以地图未完成加载,但我没有收到任何错误信息。

如果我只是简单地退出应用程序,然后再进入,地图就可以正常加载。这意味着如果从后台打开应用程序,则会加载地图。

有什么想法是什么改变了吗?在 iOS 10 中完全正常工作。

enter image description here

更新

在 iOS 11 中 mapViewWillStartLocatingUser 被调用,但没有调用 mapViewWillStartRenderingMap。我想知道是否需要手动调用某些内容以启动地图的渲染。在 iOS 9(我的测试环境,也完全正常工作),mapViewWillStartRenderingMapmapViewWillStartLocatingUser 之前被调用。


现在我正在等待看看它是否会在以后的测试版中解决。否则,我将继续努力寻找解决方案。 - Christoffer
这在新的Xcode版本中仍然是一个问题,很遗憾。@onmyway133,你找到解决方案了吗? - Christoffer
mapViewWillStartLoadingMap或mapViewDidFailLoadingMap是否被调用过? - Navillus
@Navillus 不,它们不会在第一次运行时被调用。只有当我关闭应用程序并再次打开它时才会被调用。 - Christoffer
@Christoffer 我也在开发地图应用,但是我的应用即使第一次运行也能正常工作。你能提供更多关于你的代码的信息吗?另外,你是在Storyboard中创建地图还是通过编程创建的? - Akshay Sunderwani
显示剩余3条评论
4个回答

0

我曾经遇到完全相同的问题,花费了很多时间寻找解决方案,最终我找到了。 在我的情况下,问题在于错误的初始化。通常您会在viewController的顶部编写“let mapView = MKMapView()”,然后在viewDidLoad内的某个位置进行自定义,但是在IOS 11 Beta 1之后它停止工作。 我通过将其更改为“var mapView:MKMapView?” 整理了viewController的顶部,然后在viewDidLoad中,像mapView = MKMapView()这样对其进行初始化。希望能帮助到某个人!:)


0

我认为你应该尝试通过移除

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

}

将以下代码放入您的View Didload方法中。
    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)];

1
不确定您的意思。用户位置可以正常工作,并且也显示在“地图”上,就像您在上面的图片中看到的那样。您是指这个吗? - Christoffer
哦,抱歉。你能不能在viewWillAppear中尝试重新加载地图?因为显然没有问题。 - Abu Ul Hassan
请给我一些时间,我正在演示中尝试它。 - Abu Ul Hassan
我无法在演示中运行它,因为有太多依赖代码。不幸的是,但我正在努力找到问题并与您分享。 - Abu Ul Hassan
是的,对此我很抱歉。这是一个复杂的项目 :/ 我已经尝试在viewWillAppear和viewDidAppear中使用'[self.mapView setRegion:self.mapView.region animated:true];'重新加载地图,但没有任何作用。 - Christoffer
让我们在聊天中继续这个讨论:点击此处进入聊天室 - Christoffer

0

确保您不要在地图上使用dispatch_async。

我有以下函数,在iOS11中无法正常工作

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

已更改为

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

0

我也有同样的问题,我的代码有些错误:

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
    }
}

事实证明,在iOS 11中,MKMapView在视图控制器加载(即viewDidLoad())之前初始化会出问题,所以我们需要进行修复:

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
        ...
    }
}

我也尝试将它放在初始化方法中,但对我来说并没有起作用:

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()
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接