嗨,我有一個CGPDFDocument對象。我想通過在我的應用程序中顯示或使用外部應用程序來打開此文檔。這是我迄今爲止的代碼。如何在swift中顯示CGPDFDocument?
// Get the document's file path.
let path = NSBundle.mainBundle().pathForResource("Newsletter.pdf", ofType: nil)
// Create an NSURL object based on the file path.
let url = NSURL.fileURLWithPath(path!)
// Create an NSURLRequest object.
let request = NSURLRequest(URL: url)
// Load the web viewer using the request object.
webView.loadRequest(request)
捆綁的PDF文檔的標題是「Newsletter.pdf」和「web視圖」是一個IBOutlet到:在SWIFT
let cfData = CFDataCreate(kCFAllocatorDefault, UnsafePointer<UInt8>(data.File.bytes), data.File.length)
let cgDataProvider = CGDataProviderCreateWithCFData(cfData)
let cgPDFDocument = CGPDFDocumentCreateWithProvider(cgDataProvider)
您想從哪裏顯示?在你的主包(項目)中有你的pdf文件嗎? – Lion