Connection to assetsd was interrupted or assetsd died

Deadly 提交于 2019-12-18 11:27:48

问题


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?

I also get this error along with it:

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

回答1:


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.

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

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




回答2:


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

create and empty array of data like this

var imgData = [Data]()

then in your viewdidload check for authorisation like this

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

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


来源:https://stackoverflow.com/questions/26658934/connection-to-assetsd-was-interrupted-or-assetsd-died

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