这是当前 PDF 阅读器的 swift 代码,必须知道文件和路径:
class ViewController: UIViewController , ReaderViewControllerDelegate{ @IBAction func didClickOpenPDF(sender: AnyObject) { let file = NSBundle.mainBundle().pathForResource("Test", ofType: "pdf") let document:ReaderDocument = ReaderDocument.withDocumentFilePath(file, password: nil) print(file) print("DOcument = ", document) if (document != "") { print("not empty") let readerViewController:ReaderViewController = ReaderViewController(readerDocument: document) readerViewController.delegate = self readerViewController.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve readerViewController.modalPresentationStyle = UIModalPresentationStyle.FullScreen [self.presentViewController(readerViewController, animated: true, completion: nil)] } }
- 这是解析数据库结构:
- 那么我如何访问和阅读“bookfile”字段并知道路径目录呢? 任何人都可以帮助并提供一些我可以使用的 swift-2 代码吗?谢谢
最佳答案
我已经完成了相同类型的功能。 试试下面的代码。可能会有所帮助。根据需要对以下代码进行要求更改。
var query = PFQuery(className:"ModelHome")
query.whereKey("guestName", equalTo:"Sean Plott")
query.findObjectsInBackgroundWithBlock
{
(objects: [PFObject]?, error: NSError?) -> Void in
if error == nil
{
// The find succeeded.
print("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject]
{
for object in objects
{
print(object.objectId)
//Get PDF Data from Object.
let userPDFFile = object["docs"] as PFFile
userPDFFile.getDataInBackgroundWithBlock
{
(pdfData: NSData?, error: NSError?) -> Void in
if error == nil
{
if let pdfData = pdfData
{
//Do the your required code here after getting pdf data.
}
}
}
}
}
}
else
{
// Log details of the failure
print("Error: \(error!) \(error!.userInfo!)")
}
}
关于ios - 我有 Github PDF 阅读器使用我的 Swift 代码和 Test.pdf 文件,但是如何读取存储在 Parse 数据库中的 pdf 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33838786/