• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Unable to extract JPEG from PHAsset
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unable to extract JPEG from PHAsset


  • Subject: Unable to extract JPEG from PHAsset
  • From: Glen Huang <email@hidden>
  • Date: Fri, 16 Jun 2017 22:31:42 +0800

Hi,

I'm trying to extract the JPEG data from a PHAsset. I did it like this:

            let fetchOptions = PHFetchOptions()
            fetchOptions.sortDescriptors = [NSSortDescriptor(key:
"creationDate", ascending: true)]
            let assets = PHAsset.fetchAssets(with: fetchOptions)
            jpg(for: assets[0])

where jpg(for:) is

    func jpg(for asset: PHAsset) {
        let size = CGSize(width: 100, height: 100)
        PHImageManager.default().requestImage(for: asset, targetSize: size,
contentMode: .aspectFit, options: nil) { image, info in
            if let image = image {
                let jpg = UIImageJPEGRepresentation(image, 0.8)!
            }
        }
    }

It works in the simulator running iOS 11, but fails on iPhone 5S every time with

fatal error: unexpectedly found nil while unwrapping an Optional value

And the thing caused that error was the bang after the
UIImageJPEGRepresentation function.

I'm using Xcode 9 beta, Swift 4, new build system, and the phone runs iOS 10.3.2

Any idea why that happens and how I can extract the JPEG data from PHAsset?

Thank you.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Unable to extract JPEG from PHAsset
      • From: David Duncan <email@hidden>
  • Prev by Date: APFS
  • Next by Date: Deep linking from 1 tvOS app to another
  • Previous by thread: Re: APFS
  • Next by thread: Re: Unable to extract JPEG from PHAsset
  • Index(es):
    • Date
    • Thread