Reputation: 382
I am trying to load base64 encoded data in a webview.Following is the code i am using
NSDictionary *fileFormatDic=[[NSDictionary alloc]initWithObjectsAndKeys:@"text/html",@"html",@"mage/jpeg",@"jpe",@"image/jpeg",@"jpeg",@"image/jpeg",@"jpg",@"application/pdf",@"pdf",@"application/vnd.ms-powerpoint",@"pdf",@"text/plain",@"txt",@"application/vnd.ms-excel",@"xls",@"application/msword",@"doc",nil];
NSData *fileData= [dbServiceMgr getDocumentDataForTheTaskId:[_fileDetailsDic objectForKey:@"taskId"] andFileId:[_fileDetailsDic objectForKey:@"fileId"]];
NSLog(@"filedata length---%d",fileData.length);
NSString *mimeType=[fileFormatDic objectForKey:[_fileDetailsDic objectForKey:@"fileFormat"]];
[_webView loadData:fileData MIMEType:mimeType textEncodingName:@"Base64" baseURL:nil];
But nothing is displayed in my webview. Can someone tell me, what is going wrong. Thanks in advance
Upvotes: 0
Views: 1727
Reputation: 9231
I'm not sure that this is the reason for which you get a white screen (could be) but you must understand that textEncodingName
expects a text encoding (meaning a method to encode a Unicode string to byte sequences) and you are providing a binary data-to-text encoding. So it's a different kind of encoding so to speak. Valid values would be UTF8 or UTF16 (althoulgh UTF8 is what you usually want). So, you should first decode your Base64 data and then present it to the screen.
You can read more about Unicode encodings here.
Upvotes: 1