从iOS应用程序自动打开.ibooks文件(Swift)
问题描述:
我想打开iBooks App中的特定文件。我正在使用UIDocumentsIntractionController将此文件发送给iBooks App。我的代码:从iOS应用程序自动打开.ibooks文件(Swift)
class ViewController : UIViewController {
...
...
@IBOutlet var iBooksBtn: UIButton!
@IBAction func book(sender: AnyObject) {
let ibookPath = NSBundle.mainBundle().pathForResource("test1",ofType: "ibooks")!
interactionController = UIDocumentInteractionController(URL: NSURL(fileURLWithPath:ibookPath))
interactionController.UTI = "com.apple.ibooks"
interactionController.presentOpenInMenuFromRect(CGRectZero,inView:self.iBooksBtn, animated:false)
}
...
...
}
所以,现在我存储在mainBundle这个文件,但在未来,我想从互联网上下载它。所以,当我按下按钮,我得到一些结果 选择:
,但我想打开此文件只用iBooks的和不要求选择应用(上图)。据我所知,我需要使用UTI * .ibooks文件,我猜UTI,我用的是错误的。谢谢你的帮助。另外自定义URL方案(ibooks://等)不适合我。
答
要打开iBooks的,你应该使用自定义URL方案:
打开库:
NSString *stringURL = @"ibooks://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
要打开iBooks商店在特定的书页,你已经到了完整的URL添加到特定的书:
NSString *stringURL = @"itms-books://itunes.apple.com/de/book/marchen/id436945766";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
NSString *stringURL = @"itms-bookss://itunes.apple.com/de/book/marchen/id436945766";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
+0
正如我所说,这个方案不适合我。如果我从iBook App中删除图书,然后尝试在我的应用程序中重新打开它,我什么都没有(iBooks App已打开,但没有我的书) –
'UIDocumentsIntractionController'将显示注册处理UTI的所有应用程序。因此,您可以在工作表中看到副本。现在有方法可以使用'UIDocumentsIntractionController'打开其他iBook。另外,您还希望通过检查iBooks URL方案来确保用户安装了iBooks。 – rckoenes
嗨!你有没有找到解决方案? –