[英]WKWebView not displaying pdf files in web view after app update
I just recently updated my app, and when I did so, I noticed that a web view that had been working just fine before the update no longer displays pdfs as it should.我刚刚更新了我的应用程序,当我这样做时,我注意到在更新之前运行良好的 web 视图不再显示应有的 pdf。 I made no modification to this portion of my code, so I'm guessing that this is an issue I'm having with with the current version of iOS, Swift, or both.
我没有修改这部分代码,所以我猜这是我在当前版本的 iOS、Swift 或两者中遇到的问题。
I'm running iOS 15 and Xcode 12.5.1我正在运行 iOS 15 和 Xcode 12.5.1
I also notice that if I revert to the old deprecated UIWebView, and change "characterEncodingName" to "textEncodingName" then it works just fine.我还注意到,如果我恢复到不推荐使用的旧 UIWebView,并将“characterEncodingName”更改为“textEncodingName”,那么它就可以正常工作。 But I'm not happy with this solution, because I'm not thrilled with reverting to deprecated code.
但我对这个解决方案并不满意,因为我对恢复到已弃用的代码并不感到兴奋。 I'm copying the code below that no longer works.
我正在复制下面不再有效的代码。 Any feedback would be greatly appreciated.
任何反馈将不胜感激。
import Foundation
import UIKit
import Parse
import MessageUI
import WebKit
class DocView: UIViewController, MFMailComposeViewControllerDelegate {
@IBOutlet var webView: WKWebView!
@IBOutlet var emailButton: UIBarButtonItem!
@IBOutlet var navBar: UINavigationItem!
var selectionPrev : String = String()
var attachment : Data = Data()
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = false
self.navBar.title = selectionPrev
var query : PFQuery = PFQuery()
do {
let predicate = NSPredicate(format:"docName = %@", selectionPrev)
query = PFQuery(className: "ParseDocs", predicate: predicate)
query.limit = 1000
let docsArray = try query.findObjects()
for item in docsArray {
let doc = item["docFile"] as! PFFile
doc.getDataInBackground(block: {
(imageData: Data?, error: Error?) -> Void in
if (error == nil) {
self.attachment = imageData!
self.webView.load(imageData!, mimeType: "application/pdf", characterEncodingName: "utf-8", baseURL: URL(string: "http://www.dummyaddress.com")!)
} else {
print("error")
}
})
}
} catch {
print("Error")
}
webView.contentMode = .scaleAspectFill
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.