【发布时间】:2014-03-10 03:39:55
【问题描述】:
我在 UIWebView 和 UIButton 中显示 PDF 文件列表。当我点击按钮时,我需要将我的 PDF 文件保存到 iBooks,以后用户可以从 iBooks 中阅读。
下面是我的代码:
NSString *path = [[NSBundle mainBundle] pathForResource:@"mypdf" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
[[webView scrollView] setContentOffset:CGPointMake(0,500) animated:YES];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.scrollTo(0.0, 50.0)"]];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
供下载的UIButton:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(download:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[webView addSubview:button];
-(void)download:(id)sender{
}
【问题讨论】:
-
为什么不使用
UIDocumentInteractionController并让用户选择如何处理 PDF。 -
@rmaddy:我的要求是需要下载并保存到 iBooks。以后可以阅读。点击下载按钮时是否可以将 PDF 保存到 iBooks 中?
-
@rmaddy:谢谢。但是没有可用的 API 直接存储到 iBooks。因此,我们使用 UIDocumentInteractioncontroller 让用户在应用程序中打开 iBooks。我说的对吗?
标签: ios iphone pdf uiwebview ibooks