我正在尝试获取每个 Assets 的网址,以便可以使用 AFHTTPRequestOperation 发送图像,但我无法从照片位置字符串数组中获取网址列表
这是到目前为止我的代码(不起作用由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[NSURL defaultRepresentation]:无法识别的选择器发送到实例0x17ed8170'
):
NSLog(@"photos::%@",photoUrls);
for (id photos in photoUrls){
ALAsset *asseturl = [NSURL URLWithString:photos];
NSLog(@"photoURL::%@",asseturl.defaultRepresentation.url);
照片日志如下所示:
photos::(
"assets-library://asset/asset.JPG?id=CE8A426B-3B59-4172-8761-CC477F3BB3EE&ext=JPG",
"assets-library://asset/asset.JPG?id=F4B68A42-1CA0-4880-9FB5-177CB091A28C&ext=JPG"
)
所以基本上我需要每个 Assets 的网址,以便我可以发送它们,但我无法弄清楚如何做到这一点?我认为我需要做的就是将字符串 url 数组转换为 Assets 数组,但不知道如何转换
更新的代码:
NSURL *asseturl = [NSURL URLWithString:photos];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:asseturl resultBlock:^(ALAsset *asset)
{
}
failureBlock:^(NSError *error)
{
// error handling
NSLog(@"failure-----");
}];
最佳答案
您为什么认为这是有效的:
ALAsset *asseturl = [NSURL URLWithString:photos];
您无法将 NSURL
对象分配给 ALAsset
变量并期望它神奇地更改为该类型。
您需要使用ALAssetsLibrary
方法assetForURL:resultBlock:failureBlock:
。结果 block 将为您提供所请求的 NSURL
的 ALAsset
。
关于ios - 从 url 获取 alasset 对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20955596/