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

后端 未结 3 1795
轻奢々
轻奢々 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:38

    Swift 3

    var docController: UIDocumentInteractionController?
    
    if let path = Bundle.main.path(forResource: "book", ofType: "pdf") {
            let targetURL = NSURL.fileURL(withPath: path)
    
            docController = UIDocumentInteractionController(url: targetURL)
    
            let url = NSURL(string:"itms-books:")
    
            if UIApplication.shared.canOpenURL(url! as URL) {
    
                docController!.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
            }
        }
    

提交回复
热议问题