내 iOS 프로젝트에서 파일 (.txt, .pdf, .docx, .xlsx 등) 미리보기에 QLPreviewController를 사용해 보았지만 잘 작동하지 않습니다. iOS 11 : 사용하는 장치 나 시뮬레이터가 무엇이든 빈 페이지가 표시됩니다. iOS 10.3.1 (시뮬레이터)에서는 잘 작동하며 모든 것이 정상입니다.iOS/Swift : QLPreviewController가 iOS11에서 빈 페이지를 표시합니다.
아래의 세부 정보입니다 :
환경 :
Xcode version: 8.3.3, 9.0.1
Device: iPhone 7 Plus, Simulator
iOS version: 11.0.3(iPhone 7 Plus), 10.3.1(Simulator), 11.0.1(Simulator)
Swift version: 3.1/3.2
코드
import UIKit
import QuickLook
class QuickViewController: UIViewController {
var url: String!
var filePath: URL!
var msg: Message! {
didSet {
url = msg.content
// create document folder url
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
// let tempDirectory = URL(fileURLWithPath: NSTemporaryDirectory())
filePath = documentsURL.appendingPathComponent((msg.content as NSString).lastPathComponent)
}
}
@IBOutlet weak var contentView: UIView!
// MARK: - Initialisation
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
loafFile()
}
func loafFile() {
if FileManager.default.fileExists(atPath: filePath.path) {
quickLookFile()
} else {
AppManager_Inst.download(url: "\(url!)", destinationUrl: filePath, completion: { [unowned self](succeed, msg) in
if succeed {
self.quickLookFile()
} else {
print(msg)
}
})
}
}
func quickLookFile() {
print(filePath.path)
/// Trying to read the file via FileManager to check if the filePath is correct or not
let data = FileManager.default.contents(atPath: filePath.path)
print(data)
if QLPreviewController.canPreview(filePath as NSURL) {
let QLController = QLPreviewController()
QLController.delegate = self
QLController.dataSource = self
QLController.view.frame = self.contentView.frame
self.view.addSubview(QLController.view)
} else {
print("file cannot to preview")
}
}
}
extension QuickViewController: QLPreviewControllerDataSource, QLPreviewControllerDelegate {
// QLPreviewControllerDataSource
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
return 1
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
return filePath as NSURL
}
// QLPreviewControllerDelegate
func previewController(_ controller: QLPreviewController, shouldOpen url: URL, for item: QLPreviewItem) -> Bool {
return true
}
}
나는, 내가 잘못 여기 없거나 뭔가 무엇인지하시기 바랍니다 아니에요 도움.
p .: iPhone 5c (iOS 10.3.1)에서 코드를 시험해 볼 것이므로 그 결과는 일단 여기까지 업데이트해야합니다.
안녕하세요, 귀하의 제안대로 시도했지만 작동하지 않습니다. 하지만 'addChildViewController (QLController)'를 추가하면 작동합니다. 그래서 나는 당신이 정확한 방향을 알려줌으로써 당신의 대답을 받아 들일 것입니다. 고마워요. – Raniys