EDIT: There was something wrong with my Base64 decoding. I searched for a external Base64 decoder and it working just like this:
This is the case: I have a Base64 encoded byte array I get from a webservice and convert it to NSData:
NSData *data = [Base64 decodeBase64WithString:response];
And in my Webview Controller I declared:
[webview loadData:fileData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
fileData is the decoded data.
When I run this I get a gray screen.
So I assume I'm not giving it a correct NSData
object.
I already answered my own question when I was typing it.
So I assume I'm not giving it a correct
NSData
object.
My Base64 decoding was wrong.
Using this statement works like a charm:
[webview loadData:fileData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
I'm just posting so other people can look at it of they have the same problem.
[webView loadata:data MIMEType:@"application/pdf" textEncodingName:@"UTF-8" baseURL:nil];
That should do the trick for you, if it doesn't you can write it to a file as V1ru8 suggests, but that is an extra step in most of the cases.
Hope this will helps
In addition to the already provided answers, I've found that loading NSData*
into a UIWebView
in the initializer function of a containing UIViewController doesn't work and there'll be no error.
The NSData*
needs to be loaded into the UIWebView
in the viewDidLoad
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With