I'm attempting to pull down a binary file (from Salesforce) and display it in a UIWebView. However, it it showing up blank. Here's the code I'm currently running:
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)
}
}
However, the UIWebView
comes up blank.
The value of fileData
is <d0cf11e0 a1b11ae1...00000000 0000c700 00000000>
and the fileType
is application/msword
Does anyone have some ideas how to get this to render properly?
You should see at least the binary data of your file, if the webview can't properly render it.
However,
self.view.frame
might not be properly set in viewDidLoad
. Try setting the webView
frame in viewWillAppear also.webView
to the view
.