DragonCherry / AssetsPickerViewController

Powerfully Customizable - Multiple Photo & Video Picker Controller
MIT License
386 stars 137 forks source link

Crash in iOS14 if requestAuthorization PHAccessLevel set to .addOnly #94

Open Hastingou opened 3 years ago

Hastingou commented 3 years ago

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

gezihuzi commented 3 years ago

Hi, can you provide the crash stack information?

Hastingou commented 3 years ago

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:

0 0x00007fff2f41fac0 in _swift_runtime_on_report ()

1 0x00007fff2f49a0e3 in _swift_stdlib_reportFatalErrorInFile ()

2 0x00007fff2f129f70 in closure #1 in closure #1 in closure #1 in assertionFailure(:_:file:line:flags:) ()

3 0x00007fff2f129ac7 in closure #1 in closure #1 in assertionFailure(:_:file:line:flags:) ()

4 0x00007fff2f1297a3 in closure #1 in assertionFailure(:_:file:line:flags:) ()

5 0x00007fff2f129421 in assertionFailure(:_:file:line:flags:) ()

6 0x00000001075c23eb in closure #1 in AssetsManager.fetchAssets(isRefetch:completion:) at /Users/SiriusStar/Documents/PickerTest/Pods/AssetsPickerViewController/AssetsPickerViewController/Classes/Assets/AssetsManager.swift:658

7 0x00000001075c084e in closure #3 in closure #1 in AssetsManager.fetchAlbums(isRefetch:completion:) at /Users/SiriusStar/Documents/PickerTest/Pods/AssetsPickerViewController/AssetsPickerViewController/Classes/Assets/AssetsManager.swift:606

8 0x000000010758ec40 in thunk for @escaping @callee_guaranteed () -> () ()

9 0x00000001077e17ec in _dispatch_call_block_and_release ()

10 0x00000001077e29c8 in _dispatch_client_callout ()

11 0x00000001077f0e75 in _dispatch_main_queue_callback_4CF ()

12 0x00007fff2038bdab in CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE ()

13 0x00007fff2038662e in __CFRunLoopRun ()

14 0x00007fff203856c6 in CFRunLoopRunSpecific ()

15 0x00007fff2b76adb3 in GSEventRunModal ()

16 0x00007fff24675187 in -[UIApplication _run] ()

17 0x00007fff2467a038 in UIApplicationMain ()

18 0x00007fff541545f2 in UIApplicationMain(::::) ()

19 0x000000010730236a in static UIApplicationDelegate.main() ()

20 0x00000001073022de in static AppDelegate.$main() ()

21 0x00000001073023b9 in main ()

22 0x00007fff20256409 in start ()

23 0x00007fff20256409 in start ()

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.

gezihuzi commented 3 years ago

Thank you for the information, I will try to reproduce and see if I can fix this issue.

KrishnaKaira commented 3 years ago

@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.

KrishnaKaira commented 3 years ago

@gezihuzi Did you get a chance to check and test the suggested change?