Open Hastingou opened 3 years ago
Hi, can you provide the crash stack information?
Logs:
2020-12-14 09:26:29.030164+0800 PickerTest[1738:38344] 💥AssetsManager.fetchDefaultAlbums:714 - Is this case could happen? Please raise an issue if you've met this message. 2020-12-14 09:26:29.033768+0800 PickerTest[1738:38344] 💥AssetsManager.fetchDefaultAlbums:714 - Is this case could happen? Please raise an issue if you've met this message. 2020-12-14 09:26:29.041570+0800 PickerTest[1738:38756] 💥AssetsManager.fetchAlbumsAsync:820 - Is this case could happen? Please raise an issue if you've met this message. 2020-12-14 09:26:29.043202+0800 PickerTest[1738:38344] 💥AssetsManager.fetchDefaultAlbums:714 - Is this case could happen? Please raise an issue if you've met this message. 2020-12-14 09:26:29.044023+0800 PickerTest[1738:38756] 💥AssetsManager.fetchAlbumsAsync:820 - Is this case could happen? Please raise an issue if you've met this message. 2020-12-14 09:26:29.052327+0800 PickerTest[1738:38344] 💥AssetsManager.fetchDefaultAlbums:714 - Is this case could happen? Please raise an issue if you've met this message. Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file AssetsPickerViewController/AssetsManager.swift, line 658 2020-12-14 09:26:29.054075+0800 PickerTest[1738:38174] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file AssetsPickerViewController/AssetsManager.swift, line 658
Thread information:
A demo video about crash is here. https://youtu.be/dI-vQ-xMtyk
Crash reason is because .addOnly setting will lead two authorization request in iOS 14. If you deny the first but allow the second ,then will crash.
To fix it just set .addOnly to .readWrite in file AssetManager.swift.
PHPhotoLibrary.requestAuthorization(for: .readWrite, handler: { (status) in DispatchQueue.main.async { switch status { case .authorized, .limited: completion(true) default: completion(false) } } })
By the way, this crash is not just happens on Simulator. Using simulator to create the demo video just for convenience.
Thank you for the information, I will try to reproduce and see if I can fix this issue.
@gezihuzi I encountered the same crash and investigated the issue upon which I also came to same conclusion as suggested by @Hastingou. Kindly update the library with the same changes.
@gezihuzi Did you get a chance to check and test the suggested change?
AddOnly is a wrong setting in this framework, change it to readWrite please.
When Photo Setting set to addOnly, this lead to cameraRollAlbum in AssetsManager to nil, then crash