如何查看NSData的组件?

时间:2011-06-29 21:01:36

标签: pdf nsdata

我正在尝试从NSData写一个PDF文件,我从http请求中获取,然后显示pdf。当我打电话给[响应说明]时,我得到< 30>,所以我至少得到了回报。但是,当我运行此代码时,出现错误:“找不到PDF标题:'%PDF'未找到。”

如果不是pdf,有没有办法看看我的NSData是什么?我错了吗?谢谢!

 NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

if (response) {
    NSString *description = [response description]; 
    NSLog(@"description: %@", description);  //this prints: <30>
} else {
    NSLog(@"response is nil");
}

NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                    NSUserDomainMask, YES); 

NSString *filename = @"Test1.pdf"; 

NSString *dirPath = [dirs objectAtIndex:0]; 

NSError *error = nil;
NSString *path=[dirPath stringByAppendingPathComponent:filename];
[response writeToFile:path atomically:YES];
NSLog(@"Write returned error: %@", [error localizedDescription]);

NSURL *pdfUrl = [NSURL fileURLWithPath: path];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];

0 个答案:

没有答案