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];
        }
    }
}];
4

1 回答 1

0

没有官方方法可以从应用程序内部以编程方式设置壁纸(或将图像/视频添加到壁纸列表中)。您可以实现的最接近的是将其保存到相机角色,然后让用户从那里将其设置为墙纸。

但是,我相信 Apple 在他们的一些广告中使用了私有 API 来实现这一点,但这没有记录在案,使用它会导致您的应用程序被应用商店拒绝批准。

于 2016-06-27T09:25:06.727 回答