小编Med*_*dwe的帖子

错误:启动 MKMapSnapshotter 时“连接到名为 com.apple.MapKit.SnapshotService 的服务”

我尝试创建我的地图视图的快照以供稍后显示,因此我没有另一个地图视图浪费内存。

大多数情况下它工作得很好,但最近我尝试创建巴黎的快照并得到错误:“连接到名为 com.apple.MapKit.SnapshotService 的服务”。

我知道它看起来像是剪掉了一部分,但不,这似乎是整个错误描述。

完整错误:

错误域=MKErrorDomain 代码=1 "(null)" UserInfo=。{NSUnderlyingError=0x284562610 {Error Domain=NSCocoaErrorDomain Code=4097“连接到名为 com.apple.MapKit.SnapshotService 的服务” UserInfo={NSDebugDescription=连接到名为 com.apple.MapKit.SnapshotService 的服务}}}

我已经尝试过多次,但似乎在拍摄巴黎的快照时,它永远不会像其他城市那样奏效。我真的不知道从哪里开始解决问题,因为我没有找到任何关于我的错误来源的信息。

编辑:这种行为实际上在其他城市也似乎是随机的。

在 viewDidLoad 中,我像这样初始化我的选项对象:

snapShotOptions.size = mapView.frame.size
snapShotOptions.scale = UIScreen.main.scale
snapShotOptions.showsBuildings = false
Run Code Online (Sandbox Code Playgroud)

When the user now decides to go on, I initialize & start the snapshotter and handle data accordingly, before that I also set the region for the snapshot:

snapShotOptions.region = mapView.region
snapShotter = MKMapSnapshotter(options: snapShotOptions)

// Take a snapshot.
snapShotter.start { (snapshot, error) -> Void in
    if error …
Run Code Online (Sandbox Code Playgroud)

mapkit mkmapview ios swift

9
推荐指数
1
解决办法
342
查看次数

UICollectionViewDiffableDataSource cellProvider 比预期更频繁地调用

我正在使用 UICollectionViewDiffableDataSource 来填充我的 UICollectionView。通过 REST API 收到项目列表后,我创建了一个新快照并像这样应用它:

DispatchQueue.main.async {
   var snapshot = NSDiffableDataSourceSnapshot<RegionSection, DiffableModel>()
   snapshot.appendSections(RegionSection.allCases)
   snapshot.appendItems(self.spotlights, toSection: .Spotlights)
   snapshot.appendItems(self.vendors, toSection: .Vendors)
   self.dataSource?.apply(snapshot, animatingDifferences: animated)
}
Run Code Online (Sandbox Code Playgroud)

在 cellProvider 中设置我的单元格时,我从 URL 异步加载图像。我注意到,第一个单元格会疯狂地浏览所有加载的图像,并最终显示与预期不同的图像。(例如,要由最后一个单元格显示的图像)。

我决定调查并发现cellProvider 闭包的调用次数是预期的两倍。此外, collectionView.dequeueReusableCell 函数在调用的前半部分表现得很奇怪,因为它每次都返回相同的单元格,即使 collectionView 中没有可以出队的单元格。

我的 cellProvider 关闭:

dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { (collectionView, indexPath, entry) -> UICollectionViewCell? in
    if let spotlight = entry as? Spotlight{
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "spotlightCell", for: indexPath) as! SpotlightCell
        
        cell.nameLabel.text = spotlight.title
        cell.subtitleLabel.text = spotlight.subtitle
        cell.categoryLabel.text = spotlight.type.getDescription().uppercased()
        cell.imageView.loadImage(fromUrl: spotlight.titlePictureUrl)
                    
        return …
Run Code Online (Sandbox Code Playgroud)

uikit uicollectionview uicollectionviewcell swift uicollectionviewdiffabledatasource

5
推荐指数
1
解决办法
293
查看次数