Exemple #1
0
        public static async Task <string> GetIOSFilePath(this PHAsset photo)
        {
            var tcs = new TaskCompletionSource <NSUrl>();

            if (photo.MediaType == PHAssetMediaType.Image)
            {
                var options = new PHContentEditingInputRequestOptions();
                options.CanHandleAdjustmentData = _ => true;
                photo.RequestContentEditingInput(options, (contentEditingInput, requestStatusInfo) => {
                    tcs.SetResult(contentEditingInput.FullSizeImageUrl);
                });
            }
            else if (photo.MediaType == PHAssetMediaType.Video)
            {
                var options = new PHVideoRequestOptions();
                options.Version = PHVideoRequestOptionsVersion.Original;
                PHImageManager.DefaultManager.RequestAvAsset(photo, options, (asset, audioMix, info) => {
                    if (asset is AVUrlAsset urlAsset)
                    {
                        tcs.SetResult(urlAsset.Url);
                        return;
                    }
                    tcs.SetException(new InvalidDataException("RequestAvAsset didn't get AVUrlAsset"));
                });
            }
            var origfilepath = await tcs.Task.ConfigureAwait(false);

            return(origfilepath.Path);
        }
        private Task <string> GetFilePathFromAssetAsync(PHAsset phAsset)
        {
            var tcs = new TaskCompletionSource <string>();

            phAsset.RequestContentEditingInput(
                new PHContentEditingInputRequestOptions(),
                (input, v) =>
            {
                var filePath = input.FullSizeImageUrl.Path;
                tcs.TrySetResult(filePath);
            });
            return(tcs.Task);
        }