xcode 与 assetsd 的连接中断或 assetsd 死亡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26658934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:03:20  来源:igfitidea点击:

Connection to assetsd was interrupted or assetsd died

iosxcodeswiftuikitphasset

提问by Aggressor

I load photos from PHAssets. I get this error log when I load some images and pass them to another view controller. I can't seem to find anything online about this. Anyone encounter this and know what it is?

我从 PHAssets 加载照片。当我加载一些图像并将它们传递给另一个视图控制器时,我会收到此错误日志。我似乎无法在网上找到关于此的任何信息。任何人遇到这个并知道它是什么?

I also get this error along with it:

我也收到了这个错误:

***** Error: logging directory does not exist /var/mobile/Library/Logs/CrashReporter/DiagnosticLogs/

回答by Shobhakar Tiwari

There may be following reason :

可能有以下原因:

1.)It may occur when we try to use multiple Image view (Image) so just image and try to release it , it will solve problem.

1.)当我们尝试使用多个图像视图(Image)时可能会发生这种情况,因此只需图像并尝试释放它,它就会解决问题。

2.)Also to avoid create too many property for storing images .

2.)还要避免为存储图像创建太多属性。

3.)If we need to send image to another view try to compress it .

3.)如果我们需要将图像发送到另一个视图,请尝试对其进行压缩。

回答by Mohammad Yunus

leaving this here hoping this could help:

把这个留在这里希望这可以帮助:

import photos

导入照片

import Photos

then in your info.plist add photo usage description this is mandatory for privacy reasons

然后在您的 info.plist 添加照片使用说明出于隐私原因这是强制性的

create and empty array of data like this

像这样创建和清空数据数组

var imgData = [Data]()

then in your viewdidload check for authorisation like this

然后在您的 viewdidload 中检查这样的授权

if PHPhotoLibrary.authorizationStatus() == .authorized{
        print("already allowed")
        getImages()
    }else{
        PHPhotoLibrary.requestAuthorization { [weak self] (newStatus) in
            if newStatus == .authorized{
                print(newStatus)
                self?.getImages()
            }else{
                print("not accepted")
            }
        }
    }

create a function

创建一个函数

func getImages(){
        let assetCollection = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumDepthEffect, options: nil).firstObject!
            let result = PHAsset.fetchAssets(in: assetCollection, options: nil)
        result.enumerateObjects { (ph_asset, int, unsafe_mutable_pointer) in
            PHImageManager.default().requestImageData(for: ph_asset, options: nil, resultHandler: { (data, string, image_orientation, info) in
                self.imageData.append(data!)
                self.imageString.append(string!)
                DispatchQueue.main.async {
                    self.myCollectionView.reloadData()
                }
            })
        }
    }

extend you view controller like below

像下面这样扩展你的视图控制器

extension ViewController: UICollectionViewDataSource, UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    print(imageData.count)
    return imageData.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CustomCVCell
    cell.myImageView.image = UIImage(data: imageData[indexPath.row])
    return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    print(indexPath.item)
    print(imageString[indexPath.item])
    if let dvc = storyboard?.instantiateViewController(withIdentifier: "Detail") as? DetailViewController{
        dvc.data = imageData[indexPath.item]
        navigationController?.pushViewController(dvc, animated: true)
    }}}

the problem could be because you are passing the image, but if you pass the data this will work, in your detailviewcontroller do this

问题可能是因为您正在传递图像,但是如果您传递数据,这将起作用,在您的 detailviewcontroller 中执行此操作

@IBOutlet weak var myImageView: UIImageView!{
    didSet{
        myImageView.image = UIImage(data: data!)
    }
}