Search code examples
iosphassetphotokitios13phimagemanager

PHImageResultIsDegradedKey/PHImageFileURLKey is not found


iOS 13 beta4 no longer gives

1) PHImageFileURLKey 2) PHImageResultIsDegradedKey in image result info keys.

Anyone knows a way to find the fileurl of the PHAsset?


Solution

  • 1.PHImageResultIsDegradedKey is now being available in latest iOS 13 GM and GM2. So one problem solved.

    2.PHImageFileURLKey won't be available in iOS 13 and if you are in so need of fileURL of an image asset and you need it without any PhotoKit's methods callback go for regex in description of asset. It will work.

    You can get the description of a PHAssetResource object using +[PHAssetResource assetResourcesForAsset:] , use first object from resulting array and then extract the fileURL from string using regex:

    public static func getFileURLFromPHAssetResourceDescription(description: String) -> String? {
        let regex = try! NSRegularExpression(pattern: "(?<=fileURL: ).*(?=\\s)")
        if let result = regex.firstMatch(in: description, options: [], range: NSRange(location: 0, length: description.count)) {
            let url = String(description[Range(result.range, in: description)!])
            return url
        }
        return nil
    }
    

    Note: Only available from iOS9