【问题标题】:download large zip file in iphone upto 50 MB iphone在 iphone 中下载最大 50 MB iphone 的大 zip 文件
【发布时间】:2010-12-30 12:07:59
【问题描述】:

我想在我的 iphone 中从服务器下载一个最大 50 mb 的大 zip 文件。所以请任何人建议我将如何下载大型 zip 文件。

我有下载普通 zip 文件的实现代码,但我想下载大文件。

【问题讨论】:

    标签: iphone ios4 zip download


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      直接取自项目:

      - (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];   
      ...
      

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-29
        • 2013-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多