Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Download 如何从服务器url加载PHLivePhoto?_Download_Phlivephoto - Fatal编程技术网

Download 如何从服务器url加载PHLivePhoto?

Download 如何从服务器url加载PHLivePhoto?,download,phlivephoto,Download,Phlivephoto,我使用这种方法将jpg和mov下载到documentdir。但是,使用photolibary中为AssetResource编写的[PhaseSetResourceManager defaultManager]来保存相同的目录并加载ok是不可行的 NSURL *url = [NSURL URLWithString:@"http://192.168.1.50/download/1.jpg"]; //NSURL *url = [NSURL URLWithString:@"http://192.16

我使用这种方法将jpg和mov下载到documentdir。但是,使用photolibary中为AssetResource编写的[PhaseSetResourceManager defaultManager]来保存相同的目录并加载ok是不可行的

 NSURL *url = [NSURL URLWithString:@"http://192.168.1.50/download/1.jpg"];
 //NSURL *url = [NSURL URLWithString:@"http://192.168.1.50/download/3.mov"];
 NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
 NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    NSHTTPURLResponse *res = (NSHTTPURLResponse *)response;
//    NSLog(@"%@",[res allHeaderFields]);
    self.receiveData = [NSMutableData data];
    self.sumLength=response.expectedContentLength;

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [self.receiveData appendData:data];


    self.currentLength+=data.length;
    double progress=(double)self.currentLength/self.sumLength;
    self.progress.progress=progress;


}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask,YES);
    NSString *ourDocumentPath =[documentPaths objectAtIndex:0];


    NSString *fileName=[ourDocumentPath stringByAppendingPathComponent:@"1.mov"];

     if ([self.receiveData writeToURL:[NSURL fileURLWithPath:fileName] atomically:YES])
     {
         NSLog(@"OK Sucess");
     }else
     {
         NSLog(@"No Fail");

     }
}

如何加载它们?谢谢。

您解决问题了吗?是的,您必须格式化jpg和视频演示:
2016-03-07 19:22:28.854 TestJiri[8641:5589436] /var/mobile/Containers/Data/Application/D100284B-74B2-41E1-B643-7B3EF71F99DE/Documents/1.jpg
2016-03-07 19:22:28.854 TestJiri[8641:5589436] /var/mobile/Containers/Data/Application/D100284B-74B2-41E1-B643-7B3EF71F99DE/Documents/1.mov
2016-03-07 19:22:28.899 TestJiri[8641:5597595] Error: Invalid video metadata