0
 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");

     }
}

I use this method download both jpg and mov to document dir. but is not work to play and use [PHAssetResourceManager defaultManager] writeDataForAssetResource from photolibary to save same dir and load ok.

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

how to load them? thanks.

jerry
  • 11
  • 3

0 Answers0