iOS 今天扩展 MapView 仅适用于 Xcode 模拟器

iOS Today Extension MapView Only Work on Xcode Simulator

我已经为我的应用程序实现了一个今日小部件。

mkmapView 在两种情况下工作正常: 1. Xcode模拟器 2. 设备运行 Xcode

但是当我通过设备本身运行小部件时,mapView 只显示背景颜色和用户的位置标记。

有人知道为什么吗?如何解决?

谢谢!

直接来自 Apple documentation

Make sure that the Today extension point is appropriate for the functionality you want to provide. The best widgets give users quick updates or enable very simple tasks. If you want to create an app extension that enables a multistep task or helps users perform a lengthy task, such as uploading or downloading content, the Today extension point is not the right choice.

MKMapView 需要在跨度或缩放时不断更改,并以尊重的方式召集代表。

这就是您在今日小部件中添加地图时看不到任何更新的原因之一。

您可以使用MKMapSnapshotter to take a snapshot of the map but I was still having some memory and autolayout (why!?!?) issues using this in a today extension. Our not-so-great-but-works solution is to use our app's background location fetching mechanism and a shared container 来存储来自 MKMapSnapshotter 的 NSData。然后在今天的扩展中,做尽可能少的工作,只是从容器中读取 NSData 并用 UIImageView 显示它。