-(IBAction)click;
{
NSURL *url = [NSURL URLWithString:URL_TO_DOWNLOAD];
NSString *tempDownloadPath = [[self documentsDirectory]
stringByAppendingPathComponent:@"test.pdf"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadDestinationPath:[self documentsDirectory]];
[request setTemporaryFileDownloadPath:tempDownloadPath];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"requestFinished");
NSError *error;
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSLog(@"Documents directory: %@", [fileManager
contentsOfDirectoryAtPath:[self
documentsDirectory] error:&error]);
NSString *dir = [self documentsDirectory];
NSLog(dir);
// NSData *responseData = [request responseData];
NSArray *array = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:dir error:&error];
if (array == nil) {
NSLog(@"array == nil");
}
else
{
[aWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:tempDownloadPath]]];
[[self view] addSubview:aWebView];
}
[fileManager release];
}
- (NSString *)documentsDirectory {
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
return [paths objectAtIndex:0];
}
我無法管理檢查文件是否存在,然後再點擊下載,或者實際顯示PDF請求已完成。任何解決方案?iphone pdf下載
我試圖修改文件來支持PDF,但是,它實際上不會通過簡單地更改文件擴展名來加載PDF .. – 2011-04-05 14:02:00
您需要使用與呈現PDF相同的方式來呈現它,查看Apple的Quartz示例 – 2011-04-07 12:06:45