PHImageResultIsDegradedKey/PHImageFileURLKey is not found

前端 未结 9 862
忘了有多久
忘了有多久 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:43

    You have to use this function from PHAsset object:

    - (PHContentEditingInputRequestID)requestContentEditingInputWithOptions:(nullable PHContentEditingInputRequestOptions *)options completionHandler:(void (^)(PHContentEditingInput *__nullable contentEditingInput, NSDictionary *info))completionHandler;
    

    Then you can retrieve URL this way:

    NSURL *url = contentEditingInput.fullSizeImageURL;
    
    0 讨论(0)
  • 2020-12-09 23:45

    Some example Objective-C code for anyone else looking for it:

    PHContentEditingInputRequestOptions *editOptions = [[PHContentEditingInputRequestOptions alloc] init];
    
    [myPHAsset requestContentEditingInputWithOptions:editOptions completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
    
        if (contentEditingInput.fullSizeImageURL) {
            //do something with contentEditingInput.fullSizeImageURL
        }
    
    }];
    
    0 讨论(0)
  • 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
        }
    
    0 讨论(0)
提交回复
热议问题