我正在尝试下拉一个二进制文件(来自 Salesforce)并将其显示在 UIWebView 中。但是,它显示为空白。这是我目前正在运行的代码:
class SRAFileViewController: UIViewController {
var webView: UIWebView!
var fileData: NSData!
var fileType: String!
convenience init(fileData: NSData!, fileType: String!, title: String!){
self.init()
self.fileType = fileType
self.fileData = fileData
self.title = title
}
override func viewDidLoad() {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "close")
self.view.backgroundColor = UIColor.whiteColor()
self.navigationItem.title = self.title
webView = UIWebView(frame: self.view.frame)
webView.delegate = self
let tempData = NSData(bytes: fileData.bytes, length: fileData.length)
webView.loadData(tempData, MIMEType: self.fileType, textEncodingName: "UTF-8", baseURL: NSURL(string: "http://localhost")!)
}
func close(){
self.dismissViewControllerAnimated(true, completion: nil)
}
}
但是,UIWebView
出现空白。
fileData
is<d0cf11e0 a1b11ae1...00000000 0000c700 00000000>
和fileType
is的值application/msword
有没有人有一些想法如何让它正确渲染?