Error when trying to save a captured image in swift

后端 未结 1 1234
囚心锁ツ
囚心锁ツ 2021-01-23 09:24

In my project, I am capturing an image. But when it starts saving the image, app crashes with the error of -

\"unexpectedly found nil while unwrapping\"

相关标签:
1条回答
  • 2021-01-23 09:54

    The problem is that you have never given self.assetCollection or self.photoAsset any value, so they are nil. Thus, when you try to use them in your PHAssetCollectionChangeRequest initializer, you crash.

    By the way, if all you want to do is save the image into the camera roll, you don't need all that code. The creation request alone is all you need.

    Or, if you want to save the image into the camera roll and into an album, you don't need to call PHAssetCollectionChangeRequest(forAssetCollection:assets:) to do it.

    Finally, you really shouldn't have all that extra stuff in the change block. Just do the change and no more. The other stuff should be in the completion block.

    0 讨论(0)
提交回复
热议问题