Code Monkey home page Code Monkey logo

Comments (5)

renssies avatar renssies commented on June 24, 2024

It is not advised to get the URL of the PHAsset. Instead, you can request a UIImage version or a plain data version using PHImageManager (yes you also use PHImageManager for video).

This also allows you to get a cropped or resized version of the image and it handles iCloud downloading for you.

If you really do want to use (which again, is not advised) use can use the PHAssetResource for a PHAsset which will return a single or multiple resources based on the PHAsset

from tatsi.

renssies avatar renssies commented on June 24, 2024

Also as a side note: PHImageManager will give an unclear error when a PHAsset's photo needs to be downloaded from iCloud AND low power mode is enabled. To get around this I've added a custom error message in the app telling the user that low power mode should be turned off to download the photo.

You can check for low power mode with the following code:

let lowerPowerModeEnabled = ProcessInfo.processInfo.isLowPowerModeEnabled

from tatsi.

ambr89 avatar ambr89 commented on June 24, 2024

Ok, thanks
I'm trying to use PHAssetResource, and obtain from this the URL.
After this, I need to show the result in a CollectionView and send all to server.

from tatsi.

ambr89 avatar ambr89 commented on June 24, 2024

Thanks a lot!
I've resolved!

func pickerViewController(_ pickerViewController: TatsiPickerViewController, didPickAssets assets: [PHAsset]) { pickerViewController.dismiss(animated:true, completion: nil) for ass in assets{ let res2:[PHAssetResource] = PHAssetResource.assetResources(for: ass) let obj = res2[0] as NSObject let strURL = obj.value(forKey: "_fileURL") as! NSURL let data = try? Data(contentsOf: strURL as URL) let img = UIImage(data: data!) } }

from tatsi.

dathu7728 avatar dathu7728 commented on June 24, 2024

This image getting URL:

Assets [<PHAsset: 0x11dc12570> 2E25AD2C-51D8-4431-882F-AC8CA2E8F65B/L0/001 mediaType=1/0, sourceType=1, (3024x4032), creationDate=2019-04-08 10:04:57 +0000, location=0, hidden=0, favorite=0 ]

This image not getting URL: (app will crash for data nil)

Assets [<PHAsset: 0x11dc065f0> 420A3B33-A758-4EC3-9DC1-D72AC88B98C9/L0/001 mediaType=1/4, sourceType=1, (1242x2208), creationDate=2019-04-11 07:14:37 +0000, location=0, hidden=0, favorite=0 ]

what are the difference b/w the above two Assets, How to resolve this issue ?

from tatsi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.