PHImageResultIsDegradedKey/PHImageFileURLKey is not found

前端 未结 9 860
忘了有多久
忘了有多久 2020-12-09 22:59

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 P

9条回答
  •  囚心锁ツ
    2020-12-09 23:45

    With the suggestion of guhan0, I made a small change. Indeed, sometimes, there are more than 1 "fileURL:...", so, I take the first when the value start with "file://" which means there is a file url. I think there is a better solution, but for now, it works well:

    private func getFileURLFromPHAssetResource(resourceDescription description: String) -> String? {
    
            let regex = try! NSRegularExpression(pattern: "(?<=fileURL: ).*(?=\\s)")
    
            for match in regex.matches(in: description, options: [], range: NSRange(location: 0, length: description.count)).lazy {
    
                let url = String(description[Range(match.range, in: description)!])
    
                if url.starts(with: "file://") { return url }
            }
    
            return nil
        }
    

提交回复
热议问题