0

http://www.vesseltracker.com/earth/vesseltrackerlight.kmzをダウンロードしようとしていますが、すべての断片を取得できません。

私は試した:

  NSData *data = [NSData dataWithContentsOfURL: serverURL options: 0 error: &error];

無駄に

その後に切り替えました

- (void)startDownloadingURL:(NSURL*) url
{
    // Create the request.
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:url
            cachePolicy:NSURLRequestUseProtocolCachePolicy
           timeoutInterval:60.0];

    // create the connection with the request
 // and start loading the data
 NSLog(@"SNNetworkController.startDownloadingURL [%@]", url);
 NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
 if (theConnection) {
  // Create the NSMutableData to hold the received data.
  // receivedData is an instance variable declared elsewhere.
  receivedData = [[NSMutableData data] retain];
    } else {
        // inform the user that the download failed.
  NSLog(@"SNNetworkController.startDownloadingURL Download failed!");
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    // This method is called when the server has determined that it
    // has enough information to create the NSURLResponse.

    // It can be called multiple times, for example in the case of a
    // redirect, so each time we reset the data.

    // receivedData is an instance variable declared elsewhere.
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    // Append the new data to receivedData.
    // receivedData is an instance variable declared elsewhere.
    [receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{
    // release the connection, and the data object
    [connection release];
    // receivedData is declared as a method instance elsewhere
    [receivedData release];

    // inform the user
    NSLog(@"SNNetworkController.didFailWithError Download failed! Error - %@",
          [error localizedDescription]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // do something with the data
    // receivedData is declared as a method instance elsewhere
    NSLog(@"SNNetworkController.downloadDidFinish Succeeded! Received %d bytes of data",[receivedData length]);

    // release the connection, and the data object
    [connection release];
    [receivedData release];
}

しかし、私は運が悪いです。常に 567 バイトかかります (約 4k のはずです)。解凍が開始されて失敗する可能性があると思います....

4

1 に答える 1

2

あなたがリストした URL を Safari でダウンロードしましたが、長さは 567 バイトしかありません。「4k」に対する期待は、Finder のリスト ビューの内容に基づいていますか? その表示は、ファイル割り当てブロック サイズのため、概算にすぎません... ファイルの実際のバイト カウントは、ファイルの [情報を見る] ウィンドウで、その値の後ろの括弧内に表示されます。

于 2010-09-27T21:41:29.407 に答える