我試圖讓每個alasset的網址,這樣我就可以AFHTTPRequestOperation發送圖像,但我有麻煩的URL列表從我的照片位置字符串數組獲取從URL中
這裏是alasset對象數組到目前爲止我的代碼(不工作Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL defaultRepresentation]: unrecognized selector sent to instance 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"
)
所以基本上我需要的網址爲每項資產這樣我就可以發送他們,我無法弄清楚如何做到這一點?我認爲,所有我需要做的是我的字符串URL的數組轉換爲資產的數組,但無法弄清楚如何
更新的代碼:
NSURL *asseturl = [NSURL URLWithString:photos];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:asseturl resultBlock:^(ALAsset *asset)
{
}
failureBlock:^(NSError *error)
{
// error handling
NSLog(@"failure-----");
}];
ok我已經添加了該方法,但是我在resultBlock中放置了什麼來獲取alasset(請參閱更新的代碼) – BluGeni
放入您需要的任何代碼以使用傳遞給該塊的'ALAsset'參數。你的失敗塊應該記錄'error'參數,以便你知道失敗的原因。 – rmaddy