gpt4 book ai didi

ios8 - 从 fetchAssetsWithALAssetURLs 返回的 PHAsset : is always nil when choosing a photo from the "My Photo Stream" album using UIImagePickerController

转载 作者:行者123 更新时间:2023-12-02 14:07:25 24 4
gpt4 key购买 nike

我使用 UIImagePickerController 让用户选择要在应用程序中共享的照片或视频。当用户在其库中选择媒体项时,我在 UIImagePickerController 的委托(delegate)方法之一中执行此代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

PHAsset *asset;
if ([info[@"UIImagePickerControllerMediaType"] isEqualToString:@"public.movie"]) {
// Video
asset = [[PHAsset fetchAssetsWithALAssetURLs:@[info[@"UIImagePickerControllerReferenceURL"]] options:nil] lastObject];

} else if ([info[@"UIImagePickerControllerMediaType"] isEqualToString:@"public.image"]) {
// Photo
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[info[@"UIImagePickerControllerReferenceURL"]] options:nil];
asset = [[PHAsset fetchAssetsWithALAssetURLs:@[info[@"UIImagePickerControllerReferenceURL"]] options:nil] lastObject];
}
}

这两个 if 语句 都适用于照片和视频,除非您从标题为“我的照片流”的相册中选择项目

当您从“我的照片流”中选择项目时,返回的PHAsset始终为nil

我发现以下问题似乎有一个可行的解决方案:ALAssetsLibrary assetForURL: always returning nil for photos in "My Photo Stream" in iOS 8.1

但是上面的链接使用了Apple不再推荐的AssetsLibrary框架:

"In iOS 8.0 and later, use the Photos framework instead of the Assets Library framework. The Photos framework provides more features and better performance for working with a user’s photo library. See Photos Framework Reference."

我需要能够返回 “我的照片流” 相册中媒体项目的 PHAsset 对象。现在,info 字典中的 UIImagePickerController 返回的引用 URL 是登录控制台的有效 URL,但是当使用此 URL 时,它是一个有效的 PHAsset 对象永远不会返回。

以下是在 didFinishPickingMediaWithInfo: 委托(delegate)方法的信息字典中返回的引用 URL 示例:

assets-library://asset/asset.JPG?id=DCF5C6E5-B4F4-4E61-9C4B-CC63E104BF2B&ext=JPG

最佳答案

这是一个错误,似乎已在最新的 iOS 8.2x 测试版中修复。

关于ios8 - 从 fetchAssetsWithALAssetURLs 返回的 PHAsset : is always nil when choosing a photo from the "My Photo Stream" album using UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27496888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com