Swift: How to Open local pdf from my app to iBooks

后端 未结 3 1797
轻奢々
轻奢々 2021-01-05 08:52

I was in objective-c before. and this code below in objective C is working fine:

in. h

@property (retain)UIDocumentInteractionController *docControll         


        
3条回答
  •  醉酒成梦
    2021-01-05 09:32

    try this:

    var docController: UIDocumentInteractionController?
    
    if let path = NSBundle.mainBundle().pathForResource("book", ofType: "pdf") {
        if let targetURL = NSURL.fileURLWithPath(path) {
    
            docController = UIDocumentInteractionController(URL: targetURL)
            let url = NSURL(string:"itms-books:");
    
            if UIApplication.sharedApplication().canOpenURL(url!) {
    
                docController!.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)
    
                println("iBooks is installed")
    
                }else{
    
                println("iBooks is not installed")
            }
    
        }
    }
    

提交回复
热议问题