如何保存直播/动画壁纸

时间:2016-06-27 09:17:02

标签: ios objective-c live-wallpaper phphotolibrary

我正在制作一张真人照片/壁纸的应用程序。我从服务器下载图像和.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];
        }
    }
}];

1 个答案:

答案 0 :(得分:0)

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

但是,我认为Apple在某些广告中使用了私有API来实现这一点,但是没有记录,使用它会导致您的应用被拒绝从应用商店批准。