Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios I';ve Github PDF reader正在使用Test.PDF文件处理我的Swift代码,但如何读取存储在Parse数据库中的PDF文件?_Ios_Swift_Pdf_Parse Platform - Fatal编程技术网

Ios I';ve Github PDF reader正在使用Test.PDF文件处理我的Swift代码,但如何读取存储在Parse数据库中的PDF文件?

Ios I';ve Github PDF reader正在使用Test.PDF文件处理我的Swift代码,但如何读取存储在Parse数据库中的PDF文件?,ios,swift,pdf,parse-platform,Ios,Swift,Pdf,Parse Platform,这是PDF阅读器的当前swift代码,必须知道文件和路径: class ViewController: UIViewController , ReaderViewControllerDelegate{ @IBAction func didClickOpenPDF(sender: AnyObject) { let file = NSBundle.mainBundle().pathForResource("Test", ofType: "pdf") let document:ReaderDoc

这是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!)")
      }
    }
    

    谢谢你的回复。很抱歉,如果让pdfData=pdf数据,我可以检查如何处理该行,因为我不熟悉swift和parse。我尝试将pdfData分配给我以前的代码let file=NSBundle.mainBundle().pathForResource(“pdfData”,类型:“pdf”)let document:ReaderDocument=ReaderDocument.withDocumentFilePath(文件,密码:nil)当我打印file=nil且系统崩溃时,出现致命错误:在ReaderDOcument行中展开可选值时意外发现nil。不用担心!我终于找到了获取url的方法。Thanks@vincent如果您对此答案有帮助,请将其标记为已接受答案。所以其他人会觉得它很有帮助。