Ios I';ve Github PDF reader正在使用Test.PDF文件处理我的Swift代码,但如何读取存储在Parse数据库中的PDF文件?
这是PDF阅读器的当前swift代码,必须知道文件和路径: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
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)]
}
}
我已经做了相同类型的功能。 试试下面的代码。也许有帮助。是否需要根据需要更改以下代码
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如果您对此答案有帮助,请将其标记为已接受答案。所以其他人会觉得它很有帮助。