ios - 我有 Github PDF 阅读器使用我的 Swift 代码和 Test.pdf 文件,但是如何读取存储在 Parse 数据库中的 pdf 文件?

标签 ios swift pdf parse-platform

  1. 这是当前 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)]
    }
    }
    
    1. 这是解析数据库结构:

db structure

  1. 那么我如何访问和阅读“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/

相关文章:

ios - Objective-C - 左下角的文本基线

ios - 在 TabBar 中的部分之间添加分隔符

swift - 如何在结构中使用 UIbutton 进行 segue

ios - RxSwift - 无法绑定(bind)自定义 UICollectionViewCell 的变量

r - 使用 R,人们如何计算 PDF 文件中的页数?

c++ - 使用 C++ 创建处理 RTL 语言和复杂脚本的 PDF

ios - iTunes Connect 的 Webhook 崩溃了吗?

objective-c - 如何从其子项访问容器 View Controller 中的工具栏?

ios - NSManagedObject 子类实现具有所需 init 的协议(protocol)的 Swift 链接器错误

ios - 如何使用 SwiftUI 按钮打开本地 PDF 文件?