Привет, я хочу показать полученные байты в консоли.
<code>
(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];
NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[receivedData length]];
NSLog(@"resourceData length: %d ", [resourceLength intValue]);
if (file) {
[file seekToEndOfFile];
}
[file writeData:data];
}
файл успешно загружен и сохранен в docoument dir, но в nslog всегда указывается длина resourceData: 0
receiveata - NSMutableData * receiveData;в .h файле
странно то, что исключенные байты работают хорошо.вот код для этого:
- (void)connection:(NSURLConnection <em>)connection didReceiveResponse:(NSURLResponse</em>)response {
localFilename = [[[url2 absoluteString] lastPathComponent] copy];
NSLog(localFilename);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0] ;
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:localFilename];
[[NSFileManager defaultManager] createFileAtPath:appFile contents:nil attributes:nil];</p>
<p>expectedBytes = [response expectedContentLength];
NSLog(@"content-length: %lli Bytes", expectedBytes);
file = [[NSFileHandle fileHandleForUpdatingAtPath:appFile] retain];</p>
<p>if (file) {</p>
<pre><code> [file seekToEndOfFile];
}
}
Может кто-нибудь помочь мне.я действительно не знаю, что я делаю неправильно
С уважением
Таммо