2010-12-30 8 views
0

私は、サーバーから最大50 MBの大きなzipファイルを自分のiPhoneにダウンロードしたいと考えています。だからplzはどのように私は大きなzipファイルをダウンロードすることを提案することができます。iphone uptoで大きなzipファイルをダウンロードします。iphone

私は通常のzipファイルをダウンロードするためのコードを実装していますが、大きなファイルをダウンロードしたいと思います。

答えて

1

が直接プロジェクトから取ら:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 

    bytesCount = bytesCount + [data length]; 
    [receivedData appendData:data]; 

    //If the size is over 10MB, then write the current data object to a file and clear the data 
    if(receivedData.length > MAX_DATA_LENGHT){ 
     [fileHandle truncateFileAtOffset:[fileHandle seekToEndOfFile]]; //setting aFileHandle to write at the end of the file 

     [fileHandle writeData:receivedData]; //actually write the data 

     [receivedData release]; 
     receivedData = nil; 
     receivedData = [[NSMutableData data] retain]; 
    } 

    [progressView setProgress:(float)bytesCount/sizeOfDownload]; 
} 


- (void)connectionDidFinishLoading:(NSURLConnection*)connection { 

    DEBUG(@"Succeeded! Received %d bytes of data",[receivedData length]); 

    // Release and clean some ivars 
    // 
    [currentConnection release]; 
    currentConnection = nil; 

    [fileHandle writeData:receivedData]; 
    [receivedData release]; 
    [fileHandle release]; 
.. 

、これがスタートダウンロードルーチンの一部です:

... 
// create a path in doc's folder and initialize the file handler 
     NSString *temporaryZipPath = [self temporaryZipPathForResource]; 
     NSMutableData *fake = [[NSMutableData alloc] initWithLength:0]; 
     BOOL result = [[NSFileManager defaultManager] createFileAtPath:temporaryZipPath 
                   contents:fake 
                  attributes:nil]; 
     [fake release]; 

     if (!result) { 
      [super showAlertWithErrorDescription:@"Error creating file"]; 
      return; 
     } 

     // 
     fileHandle = [[NSFileHandle fileHandleForWritingAtPath:temporaryZipPath] retain]; 

     // 
     NSURLRequest *request = [NSURLRequest requestWithURL:[self audioPackageURL] 
               cachePolicy:NSURLRequestReloadIgnoringCacheData 
              timeoutInterval:60.0f]; 

     currentConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

     receivedData = [[NSMutableData data] retain]; 
... 

はそれがお役に立てば幸いです。

関連する問題