Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Fix image picker crash on IOS #1051

Merged
merged 6 commits into from
Jan 9, 2019
Merged

Conversation

cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Jan 9, 2019

fix an IOS crash when the image picker got tapped multiple times. flutter/flutter#20214

When the image in the imagePicker was tapped multiple times, the delegate method didFinishPickingMediaWithInfo gets called multiple times. _result is set to nil at the end of the didFinishPickingMediaWithInfo call.
When the second didFinishPickingMediaWithInfo gets triggered, because _result is nil, crash is caused.

We can also fix it by putting the code after selection inside the completion handler, it will cause a little delay in image showing up after completion. So directly checking if _result is nil and stop the process would be more efficient.

@amirh
Copy link
Contributor

amirh commented Jan 9, 2019

Thanks!
Can you add some details in the PR description explaining the problem the solution?

Copy link
Contributor

@amirh amirh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -129,7 +129,9 @@ - (void)imagePickerController:(UIImagePickerController *)picker
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
[_imagePickerController dismissViewControllerAnimated:YES completion:nil];

if (!_result) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets mention in a comment that dismissViewControllerAnimated doesn't immediately prevents further didFinishPickingMediaWithInfo invocations.

@cyanglaz cyanglaz merged commit 61d6a1f into flutter:master Jan 9, 2019
@remosingh
Copy link

Awesome, thank you so much! I literally had this exact same bug. Will try to see if it works now.

@remosingh
Copy link

Pardon my naivety....but if I simply upgrade my flutter plugins, will this solution be there too?

@Will-W
Copy link

Will-W commented Jan 10, 2019

If you look at the 'versions' of the image_picker plugin on pub (https://pub.dartlang.org/packages/image_picker#-versions-tab-) you can see that they published a new version today. I've tested it and the issue has gone away.

@remosingh
Copy link

Thanks Will!

@cyanglaz cyanglaz deleted the imagepicker_crash branch January 11, 2019 01:49
andreidiaconu pushed a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
Fix ImagePicker Crash on IOS by checking safe guarding _result to be not nil.

The method dismissViewControllerAnimated does not immediately prevent further
didFinishPickingMediaWithInfo invocations. So the code in the delegate method get triggered multiple times if user taps multiple times. 

The crash is caused because the _result block is nil and gets called again. By safe guarding it, the code will only be triggered once and will not cause crash.

Another way to fix the crash would be put the code handling selection inside the completion handler inside the dismissViewControllerAnimated:completion method. This will cause a bit delay on user experience since the completion handler is called after dismissing view controller animation finishes. So the fix provided in this PR is favored.
andreidiaconu added a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
@arteminthesky
Copy link

@cyanglaz still reproduce in version 0.6.5+1

2020-04-21 18:10:06.706981+0400 Runner[3369:1008611] CGImageSourceCreateWithData:3273: *** ERROR: CGImageSourceCreateWithData: data is nil
2020-04-21 18:10:06.707022+0400 Runner[3369:1008611] CGImageSourceGetType:3548: *** ERROR: CGImageSourceGetType: source is nil
2020-04-21 18:10:06.707038+0400 Runner[3369:1008611] CGImageDestinationCreateWithData:3086: *** ERROR: CGImageDestinationCreateWithData: type is nil
2020-04-21 18:10:06.707051+0400 Runner[3369:1008611] CGImageDestinationAddImageFromSource:3283: *** ERROR: CGImageDestinationAddImageFromSource: destination is nil
2020-04-21 18:10:06.707067+0400 Runner[3369:1008611] CGImageDestinationFinalize:3394: *** ERROR: CGImageDestinationFinalize: destination is nil

@kpalania
Copy link

My iOS app crashes when I try to upload a file. It was working just fine before I upgraded image_picker from version ^0.6.6+4 to ^0.7.2+1. Thoughts?

[core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""
[Runner] CGImageSourceCreateWithData:3459: *** ERROR: CGImageSourceCreateWithData: data is nil
[Runner] CGImageSourceGetType:3753: *** ERROR: CGImageSourceGetType: source is nil
[Runner] CGImageDestinationCreateWithData:3838: *** ERROR: CGImageDestinationCreateWithData: type is nil
[Runner] CGImageDestinationAddImageFromSource:4038: *** ERROR: CGImageDestinationAddImageFromSource: destination is nil

@mratanpara
Copy link

mratanpara commented Jan 3, 2023

While uploading images from the gallery in IOS device getting this error.
Package version is latest ^0.8.6

[core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""
[PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x282f4ce10> accessor:<<PAApplication 0x282f08b40 identifierType:auditToken identifier:{pid:2995, version:8538}>> identifier:1BC34C1E-E012-4B4C-8EB0-B6F3FBE7B1B1 kind:intervalEvent timestampAdjustment:0 visibilityState:0 assetIdentifierCount:0 tccService:kTCCServicePhotos, error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.privacyaccountingd" UserInfo={NSDebugDescription=connection to service named com.apple.privacyaccountingd}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
8 participants