添加“在iBooks中打开”到UIWebView [英] Add "Open in iBooks" to UIWebView

查看:80
本文介绍了添加“在iBooks中打开”到UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



当在Safari中打开同一个网站并点击PDF链接时,在iBooks中打开的黑色条纹很好显示在PDF上。如下图所示:





我如何在我的应用程序中实现相同的条纹?



编辑:



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



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




  • 用户导航到PDF

  • 条纹(视图)弹出当且仅当安装了iBooks应用程序(或任何其他PDF查看器)时。

  • 点击弹出窗口中的按钮将文档传输到该应用程序并打开应用程序。


解决方案

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

  BOOL iBooksInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@ ibooks的://]]; 

您可以使用以下内容列出应用程序列表(为什么仅限iBooks?;)) / p>

  //使用UIDocInteractionController API获取支持文件类型的设备列表
NSURL * pdfURL = // your pdf链接。
UIDocumentInteractionController * docController = [UIDocumentInteractionController interactionControllerWithURL:pdfURL];

//显示支持文件类型的应用程序的下拉列表,单击列表中的项目将在传入文件时打开该应用程序。
[docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

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

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

  NSURL * iBooksURLScheme = [NSURL URLWithString:@ibooks://]; 
NSString * fileURLString = //您的文件URL为* string *
NSURL * finalURL = [iBooksURLScheme URLByAppendingPathComponent:fileURLString];

[[UIApplication sharedApplication] openURL:finalURL];


I am developing a wrapper application for a site. Basically, it opens mobile version of a site in UIWebView. Some links on the site point to PDFs.

When the same site is opened in Safari and a link to PDF is tapped a nice black stripe with "Open in iBooks" is shown over the PDF. Like on the picture below:

How could I implement the same looking stripe in my app?

EDIT:

I am not asking about how to create a black button on translucent background.

I am interested in reproducing the whole workflow:

  • User navigates to a PDF
  • A stripe (view) popups if and only if there is iBooks app (or any other PDF viewer) installed.
  • Tapping a button in popup transfers document to that app and the app opens.

解决方案

To check if iBooks is installed you can call:

BOOL iBooksInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"ibooks://"]];

You can present a list of of applications (why limit to iBooks only? ;) ) using:

//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];

Note that this doesn't work on the iOS Simulator unless you made an app that reads PDFs!

If you really want to only give the option to let the PDF to be opened in iBooks, you might want to try appending the file's URL to the @"ibooks://" scheme or the one of the other two schemes that iBooks provide (which work for books in the iBook Store but I'm not sure if it also works for other URLs) which are @"itms-books://" and @"itms-bookss://". You can then do something like:

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

[[UIApplication sharedApplication] openURL:finalURL];

这篇关于添加“在iBooks中打开”到UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆