2016-06-27 4 views
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]; 
     } 
    } 
}]; 

答えて

0

でプログラム的に壁紙を設定(または壁紙のリストに画像/動画を追加)アプリ内からする公式の方法はありません。あなたが達成できる最も近いものは、それをカメラの役割に保存し、そこから壁紙としてユーザに設定させることです。

しかし、私はアップルが広告の一部でこれを達成するためにプライベートAPIを使用していると信じていますが、これは文書化されていないため、アプリストアからの承認が拒否されます。

+0

私はビデオ(.MOV)ビデオを一緒に(ダウンロードしてドキュメントディレクトリに保存する)画像(.jpg)を使用してライブ壁紙のペアを保存しようとしましたが、イメージは正常に保存されましたが、 それが主要なポイントです。 – salmancs43

+0

あなたは**ドキュメントディレクトリに保存することができた** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **あなたが固執していたように、私は私の答えを更新します。 – Greg

+0

はい、解決策があれば教えてください。 – salmancs43