Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when trying to force unwrap fullResolution image when there is only nil #37

Closed
anfriis opened this issue Oct 28, 2015 · 4 comments

Comments

@anfriis
Copy link

anfriis commented Oct 28, 2015

The framework crashes when i pick an image from iCloud library that apparently doesn't contain a fullResolution image, which therefore crashes my app.

It happens on line 30, where fullResolutionImage() is called an force unwraps the fullResolutionImage but it is nil.

Running latest version 2.3.6

@zhangao0086
Copy link
Owner

Hi @Anders123fr
Thanks for your feedback :) I can't reproduce the issue... Can you write some test code like the following?

public private(set) lazy var fullResolutionImage: UIImage? = {
    if let originalAsset = self.originalAsset {
        if let fullResolutionImage = originalAsset.defaultRepresentation().fullResolutionImage() {
            return UIImage(CGImage: fullResolutionImage.takeUnretainedValue())
        }
    }
    return nil
}()

Let me know if that works :)

@anfriis
Copy link
Author

anfriis commented Oct 29, 2015

Hi, thanks for the quick reply!
I just tried with the code you provided, but it still crashes.

Here is the crash log:

fatal error: unexpectedly found nil while unwrapping an Optional value

EXC_BREAKPOINT 0x000000010125c4fc

Thread : Crashed: com.apple.main-thread
0  libswiftCore.dylib             4314219772 _TTSf4s_s_d_d___TFSs18_fatalErrorMessageFTVSs12StaticStringS_S_Su_T_ + 44
1  DKImagePickerController        4301767060 _TFFC23DKImagePickerController7DKAssetg19fullResolutionImageGSqCSo7UIImage_U_FT_GSqS1__ + 204
2  DKImagePickerController        4301736512 _TFC23DKImagePickerController7DKAssetg19fullResolutionImageGSqCSo7UIImage_ + 332

However if you change the line to contain a ?, it won't crash but then the image is of course still not returned:
if let fullResolutionImage = originalAsset.defaultRepresentation()?.fullResolutionImage() {

Don't know why the compiler is not telling us to do so but it works.

As the framework does not support photos from iCloud photo streams, which is requirement for my project, and because ALAssets has been deprecated in iOS 9, i have to go with another framework that uses the Photos framework as explained here:
http://stackoverflow.com/questions/18079776/how-to-get-a-alassetrepresentation-of-a-shared-photostream-alasset

Luckily my deployment target is 8.0 so i can use the CTCTAssetsPickerController: https://github.com/chiunam/CTAssetsPickerController

but this framework is great if you're building a backwards compatible app :)

@zhangao0086
Copy link
Owner

@Anders123fr
Thank you for your very useful information! Actually, I should replace the ALAssets with the Photos framework. I hope I can finish it in the coming week.
Thanks again :)

@zhangao0086
Copy link
Owner

I will release the 3.0.0 with Photos framework. develop :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants