在UIWebView中添加"在iBooks中打开"

Bob*_*sky 8 uiwebview ios

我正在为网站开发一个包装器应用程序.基本上,它在UIWebView中打开网站的移动版本.网站上的某些链接指向PDF.

当在Safari中打开相同的站点并点击PDF链接时,在PDF上显示带有"在iBooks中打开"的漂亮黑条纹.如下图所示:

在此输入图像描述

我怎么能在我的应用程序中实现相同的条纹?

编辑:

不是在询问如何在半透明背景上创建黑色按钮.

我有兴趣重现整个工作流程:

  • 用户导航到PDF
  • 当且仅当安装了iBooks应用程序(或任何其他PDF查看器)时,才会弹出条带(视图).
  • 点击弹出窗口中的按钮可将文档传输到该应用程序并打开应用程序.

Gia*_*one 24

要检查iBooks是否已安装,您可以致电:

BOOL iBooksInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"ibooks://"]];
Run Code Online (Sandbox Code Playgroud)

您可以使用以下内容显示应用程序列表(为什么仅限于iBooks?;)):

//use the UIDocInteractionController API to get list of devices that support the file type
NSURL *pdfURL = // your pdf link.
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:pdfURL];

//present a drop down list of the apps that support the file type, click an item in the list will open that app while passing in the file.
 [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
Run Code Online (Sandbox Code Playgroud)

请注意,这不适用于iOS模拟器,除非您创建了一个阅读PDF的应用程序!

如果您真的只想让选项让我们在iBooks中打开PDF,您可能想尝试将文件的URL附加到@"ibooks://"方案或iBooks提供的其他两种方案之一(它适用于iBook商店中的书籍,但我不确定它是否适用于其他网址)@"itms-books://"和@"itms-bookss://".然后你可以这样做:

NSURL *iBooksURLScheme = [NSURL URLWithString:@"ibooks://"];
NSString *fileURLString = // your file URL as *string*
NSURL *finalURL = [iBooksURLScheme URLByAppendingPathComponent:fileURLString];

[[UIApplication sharedApplication] openURL:finalURL];
Run Code Online (Sandbox Code Playgroud)

  • 只是一个旁注:UIDocumentInteractionController 的 url 必须是本地文件 url(不是用于将 pdf 下载到 UIWebView 的那个)。因此,您需要首先使用 pdf 扩展名保存下载的 pdf 数据(最好保存到您的文档目录),然后使用 [NSURL fileURLWithPath:pdfPath] 创建 url。 (2认同)