2015-11-21 19 views
0
  1. 這是PDF閱讀器的電流迅速代碼必須知道文件和路徑:我的Github PDF閱讀器與我的Swift代碼一起使用Test.pdf文件,但是如何閱讀存儲在Parse數據庫中的pdf文件?

    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)] 
    } 
    } 
    
  2. 這是解析數據庫結構:

db structure

  1. 那麼我該如何訪問並閱讀「bookfile」字段並知道路徑目錄? 任何人都可以幫助和提供一些代碼,我可以使用swift-2嗎?謝謝

回答

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!)") 
    } 
} 
+0

感謝您的回覆。 – vincent

+0

對不起,我可以檢查如何處理行 如果讓pdfData = pdf數據,因爲我是新來的迅速和解析。我嘗試將pdfData分配給我以前的代碼 let file = NSBundle.mainBundle()。pathForResource(「pdfData」,ofType:「pdf」) let document:ReaderDocument = ReaderDocument.withDocumentFilePath(file,password:nil) 當我打印文件=零和 系統崩潰致命錯誤:意外地發現零,同時在ReaderDOcument行解包可選值。 – vincent

+0

別擔心!我終於找到了一種獲取網址的方法。謝謝 – vincent