Swift3:在UIImagePickerController,didFinishPickingMediaWithInfo上,与assetd的连接被中断或assedd被终止

时间:2018-09-12 19:02:02

标签: swift3 uicollectionview phasset

我正在使用PHAssets实现存储在专用相册中的个人相册。

用户可以从相机拍摄照片以存储在此私人相册中。可以通过CollectionView在应用程序中看到此相册

当前,如果我要添加6张以上的图片,则面临以下问题:

Connection to assetsd was interrupted or assetsd died

然后在日志中

CoreData: XPC: sendMessage: failed #0
CoreData: XPC: XPC connection was invalidated
Message from debugger: Terminated due to memory issue

我试图减小要插入PHAsset中的图片的大小(使用resizeImage func),但是结果是相同的。 已拍摄照片,将其正确添加到PHAsset中,应用程序崩溃。如果我重新启动该应用程序,则可以看到添加的图片,但是如果尝试添加另一张图片,则我将面临相同的崩溃。

这是didFinishPickingMediaWithInfo的代码:

public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){

    if let image: UIImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {

        let rez_img = resizeImage(image: image, withSize: CGSize(width: 300, height: 300))

            // Create asset for the taken image and save it
            PHPhotoLibrary.shared().performChanges({
                let assetToCreate = PHAssetChangeRequest.creationRequestForAsset(from: rez_img)

                if let assetPlaceholder = assetToCreate.placeholderForCreatedAsset {
                    self.photoIdentifier = assetPlaceholder.localIdentifier // Retrive the local identifier of the photo

                     if let albumChangeRequest = PHAssetCollectionChangeRequest(for: self.assetCollection, assets: self.photosAsset) {
                        albumChangeRequest.addAssets(([assetPlaceholder] as NSArray?)!)
                     }
                }
            },
            completionHandler: {(success, error) -> Void in
                NSLog("Adding Image to library > %@", (success ? "Success":"Error"))
                DispatchQueue.main.async {
                    picker.dismiss(animated: true, completion: nil)
                }

            })//end performChanges

    }

}

在显示CollectionView之前,我可能需要释放内存吗?

0 个答案:

没有答案