How to get an ALAsset URL from a PHAsset?

后端 未结 5 1093
灰色年华
灰色年华 2020-11-27 06:36

You can do it sneakily† using the undocumented PHAsset.ALAssetURL property, but I\'m looking for something documented.


† In Objective-C, this will

5条回答
  •  醉梦人生
    2020-11-27 07:05

    Read the bottom!

    The resultHandler for PHImageManager.requestImage returns 2 objects: result and info

    You can get the original filename for the PHAsset (like IMG_1043.JPG) as well as it's full path on the filesystem with:

    let url = info?["PHImageFileURLKey"] as! URL
    

    This should work right, but for some reason Apple fucked it up. So basically, you have to copy your image to a file then access that then delete it.

    The PHImageFileURLKey is usable to get the original file name, but you cannot actually access that file. It probably has to do with the fact that code in the background can access the file while other apps can delete it.

    Think how much time you would waste figuring that out since Apple fucked up rather that just documenting it. Maybe it's sincere, maybe it's that they had different developers who didn't understand and did not want to work. Here I am working though, and Apple has how many hundreds of billions in the bank?

    Yea, sorry Apple but I do not agree when I have < 500 dollars and a net worth of less than than 1 year of 1700 subscribers paying for 1TB iCloud @ $10 a month for working for the same period of time that you have been revived from debt (2001 -> now). That was the original iPhone right? You sure are teaching them those data sizes though aren't you, scaling the iCloud monthly prices < 1% of the average US monthly income!

提交回复
热议问题