2016-05-27 5 views
1

Скачано изображение с помощью afnetworking и сохраните его. [response suggestedFilename]; Я не могу получить изображение с пути.Как получить изображение по пути

Вот методы загрузки:

- (void)startDownload:(OMImageTableViewCell *)cell { 

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; 
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; 

NSURL *url = [NSURL URLWithString:[_arrayImages objectAtIndex:cell.download.tag]]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60]; 

[cell.imagePic setImageWithURLRequest:request placeholderImage:cell.imagePic.image success:nil failure:nil]; 

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) { 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     [cell.progressDownload setProgress:downloadProgress.fractionCompleted]; 
    }); 

} destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) { 

    _documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; 
    return [_documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]]; 

} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) { 
    NSData *data = [NSData dataWithContentsOfURL:filePath]; 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     cell.imagePic.image = [UIImage imageWithData:data]; 
    }); 

    NSLog(@"File downloaded to: %@", filePath); 
}]; 
[downloadTask resume]; 

} 
+0

Как вы пытаетесь получить изображение? Вставьте код. – kelin

ответ

0

Попробуйте это:

NSFileManager *fileManager = [NSFileManager defaultManager]; 
BOOL isFileExist = [fileManager fileExistsAtPath: filePath]; 
UIImage *image; 
if (isFileExist) { 
    image = [[UIImage alloc] initWithContentsOfFile:filePath]; 
} 
else { 
    // do something. 
} 
+0

Это не помогло. Я хочу вытащить их в uitableviewcell, чтобы отражать только загруженные фотографии. –

+0

Возможно, вам нужна эта структура: https://github.com/rs/SDWebImage. Просто #import заголовок UIImageView + WebCache.h и вызовите метод sd_setImageWithURL: placeholderImage: из метода tableView: cellForRowAtIndexPath: UITableViewDataSource. Все будет обработано для вас, от асинхронных загрузок до кеширования. – Patrick

+0

Спасибо!) Это его работа) –

Смежные вопросы