- (void)viewDidLoad{
__weak typeof(self) weakSelf = self;
NSURL *url = [NSURL URLWithString:@"http://img4.duitang.com/uploads/item/201211/24/20121124112047_KUFxK.gif"];
[[SDWebImageManager sharedManager]diskImageExistsForURL:url completion:^(BOOL isInCache) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (isInCache) {
NSString *cacheImageKey = [[SDWebImageManager sharedManager]cacheKeyForURL:url];
if (cacheImageKey.length) {
NSString *cacheImagePath = [[SDImageCache sharedImageCache]defaultCachePathForKey:cacheImageKey];
if (cacheImagePath.length) {
NSData *imageData = [NSData dataWithContentsOfFile:cacheImagePath];
[strongSelf writeGifImgToAlbum:imageData];
}
}
}
}];
}
- (void)writeGifImgToAlbum:(NSData *)gifData{
//#import <AssetsLibrary/AssetsLibrary.h>
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
//#import <MobileCoreServices/UTCoreTypes.h>
NSDictionary *metadata = @{@"UTI":(__bridge NSString *)kUTTypeGIF};
[library writeImageDataToSavedPhotosAlbum:gifData metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error) {
if (!error) {
NSLog(@"保存成功");
}else{
NSLog(@"false");
}
}];
}
原文:http://www.reibang.com/p/c63343516f32
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者