0
ライブ写真/壁紙のアプリを作成しています。私はサーバーから画像と.movファイルをダウンロードしています。今、私はこれらのファイルをドキュメントディレクトリに保存することに固執しています。ライブ壁紙をドキュメントディレクトリに保存するにはどうすればいいですか?誰もがこれについてのアイデアを持っていますか教えてください。ここに私のコードはライブ/アニメーションの壁紙を保存するには
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
[downloader downloadImageWithURL:[NSURL URLWithString:imgFile]
options:0
progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (image && finished) {
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];
NSString* photoPath = [documentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.JPG",strImg]];
[data writeToFile:photoPath atomically:YES];
}
}];
NSURL *URL = [NSURL URLWithString:str];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * downloadProgress){
NSLog(@"%f",downloadProgress.fractionCompleted);
NSString * str = [NSString stringWithFormat:@"%.2f",downloadProgress.fractionCompleted];
NSDictionary * infoDict = @{@"Download": str,
@"id":uniqId};
[[NSNotificationCenter defaultCenter]
postNotificationName:@"DownloadNotification"
object:self userInfo:infoDict];
}destination:^ NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];
NSString* videoPath = [documentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.MOV",strImg]];
NSURL *videoUrl =[NSURL URLWithString:videoPath];
NSLog(@"%@",[videoUrl URLByAppendingPathComponent:videoPath]);
return videoUrl;
} completionHandler:^(NSURLResponse* response, NSURL *filePath, NSError *error) {
if(error)
{
NSLog(@"File Not Dowloaded %@",error);
[self downloadFile];
}
else {
NSLog(@"%@",filePath);
[self.downloadRecord removeObjectAtIndex:0];
if (self.downloadRecord.count > 0) {
[self downloadFile];
}
}
}];
私はビデオ(.MOV)ビデオを一緒に(ダウンロードしてドキュメントディレクトリに保存する)画像(.jpg)を使用してライブ壁紙のペアを保存しようとしましたが、イメージは正常に保存されましたが、 それが主要なポイントです。 – salmancs43
あなたは**ドキュメントディレクトリに保存することができた** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **あなたが固執していたように、私は私の答えを更新します。 – Greg
はい、解決策があれば教えてください。 – salmancs43