AFNetworking を使用してサーバーからカスタム ファイル タイプをダウンロードしようとしています - 何らかの理由で、ファイルは正常にダウンロードされたと表示されますが、結果が破損しているようです。
これは私がログに記録するものです:
2013-04-20 11:17:40.326 app[18083:907] start downloads
2013-04-20 11:17:40.392 app[18083:907] Sent 283280 of 283280 bytes, /var/mobile/Applications/187878BC-9D5A-4E1C-9EE4-34512D93BF68/Documents/theprice.cm
2013-04-20 11:17:40.393 app[18083:907] Successfully downloaded file to /var/mobile/Applications/187878BC-9D5A-4E1C-9EE4-34512D93BF68/Documents/theprice.cm
私のインターネットは高速ですが、0.04 秒で 283,280 バイトをダウンロードしたわけではありません。
ここに私のAFNetworkingコードがあります:
NSLog(@"start downloads");
NSString *urlpath = [NSString stringWithFormat:@"http://www.domain.com/ygp6bcckll8mw62.cm"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlpath]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"theprice.cm"]];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation setDownloadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes, %@", totalBytesWritten, totalBytesExpectedToWrite, path);
}];
[operation start];
ファイルの内容にアクセスしようとすると、予想どおり、空です。
これがカスタム ファイル タイプを適切にダウンロードしない理由に関するアイデアはありますか? (.cm) AFNetworking のコードに、動作がおかしくなる何かが欠けていますか?