Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-26-2010, 08:31 AM   #1 (permalink)
"Sorry, but I dont know."
 
Join Date: Dec 2009
Location: Switzerland (CH)
Age: 16
Posts: 213
mavrick3 is on a distinguished road
Default UIWebView - UTF8 encoding??

Hej,

Simple Question:

I have a UIWebView and I want that it shows a .txt file. All works fine but in germany we have some special characters like ä,ö,ü and those won't be show... I need so encode this txt-file with UTF8 but I don't know how..?

Does anyone know a solution for this problem?

Code:
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:path ofType:@"txt"]isDirectory:NO]]];
mavrick3 is offline   Reply With Quote
Old 06-26-2010, 11:30 AM   #2 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 30
raphaelharboun is on a distinguished road
Default

Quote:
Originally Posted by mavrick3 View Post
Hej,

Simple Question:

I have a UIWebView and I want that it shows a .txt file. All works fine but in germany we have some special characters like ä,ö,ü and those won't be show... I need so encode this txt-file with UTF8 but I don't know how..?

Does anyone know a solution for this problem?

Code:
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:path ofType:@"txt"]isDirectory:NO]]];
i suggest either you add a doctype to your text as an html page, and you specifies the UTF-8 format, or you could load the content of your file in a NSData object, then load the content with
[webView loadHtmlString...withBaseURL]
and in this method, when you make the NSString with the NSData, you specifie the UTF-8 encoding.
raphaelharboun is offline   Reply With Quote
Old 06-27-2010, 04:33 AM   #3 (permalink)
"Sorry, but I dont know."
 
Join Date: Dec 2009
Location: Switzerland (CH)
Age: 16
Posts: 213
mavrick3 is on a distinguished road
Default

Quote:
Originally Posted by raphaelharboun View Post
i suggest either you add a doctype to your text as an html page, and you specifies the UTF-8 format, or you could load the content of your file in a NSData object, then load the content with
[webView loadHtmlString...withBaseURL]
and in this method, when you make the NSString with the NSData, you specifie the UTF-8 encoding.
Just tried it with NSData... Works fine! Thanks!
mavrick3 is offline   Reply With Quote
Old 07-08-2010, 03:38 PM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Location: Martinique
Posts: 8
thebenjiman is on a distinguished road
Question Same problem but using UTF-8 string from sqlite

Quote:
Originally Posted by raphaelharboun View Post
i suggest either you add a doctype to your text as an html page, and you specifies the UTF-8 format, or you could load the content of your file in a NSData object, then load the content with
[webView loadHtmlString...withBaseURL]
and in this method, when you make the NSString with the NSData, you specifie the UTF-8 encoding.
I'm having the same problem with my code.. I'm getting the string from an XML then save it in a sqlite database using UTF-8 encoding. When I went to display the data I use this code:

Code:
	NSString* embedHTML = @"<html lang=\"fr\"><head><meta content=\"text/html; charset=UTF-8\" http-equiv=\"content-type\"/><meta name=\"viewport\" content=\"width=320; initial-scale=0.5; maximum-scale=1.0; user-scalable=1;\"/></head><body style=\"width:500;font-size:40px;\">%@</body></html>";  
	
	NSString *html = [NSString stringWithFormat:embedHTML,article.contentFile];
	
	CFShow(html);

        UIWebView *webView = (UIWebView *)[cell viewWithTag:7];
	[webView setAlpha:1.0];
			
	[webView loadData:[html dataUsingEncoding:NSUTF8StringEncoding]
					 MIMEType:@"text/html"
			 textEncodingName:@"UTF-8"
					  baseURL:nil];
Displaying the html string in console show a well formatted HTML code but the UIWebView doesn't interpret the HTML code nor the \xxxx codes.

The strange stuff is that it loads the pictures so it interprets the img...

Last edited by thebenjiman; 07-08-2010 at 04:34 PM.
thebenjiman is offline   Reply With Quote
Old 07-08-2010, 05:23 PM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Location: Martinique
Posts: 8
thebenjiman is on a distinguished road
Default

Quote:
Originally Posted by thebenjiman View Post
I'm having the same problem with my code.. I'm getting the string from an XML then save it in a sqlite database using UTF-8 encoding. When I went to display the data I use this code:

Code:
	NSString* embedHTML = @"<html lang=\"fr\"><head><meta content=\"text/html; charset=UTF-8\" http-equiv=\"content-type\"/><meta name=\"viewport\" content=\"width=320; initial-scale=0.5; maximum-scale=1.0; user-scalable=1;\"/></head><body style=\"width:500;font-size:40px;\">%@</body></html>";  
	
	NSString *html = [NSString stringWithFormat:embedHTML,article.contentFile];
	
	CFShow(html);

        UIWebView *webView = (UIWebView *)[cell viewWithTag:7];
	[webView setAlpha:1.0];
			
	[webView loadData:[html dataUsingEncoding:NSUTF8StringEncoding]
					 MIMEType:@"text/html"
			 textEncodingName:@"UTF-8"
					  baseURL:nil];
Displaying the html string in console show a well formatted HTML code but the UIWebView doesn't interpret the HTML code nor the \xxxx codes.

The strange stuff is that it loads the pictures so it interprets the img...
I found where was my mistake! I used another encoding when saving the string from the xml; I had to use the same encoding from the beginning to the end of the process.
thebenjiman is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 326
7 members and 319 guests
anothermine, Chickenrig, Domele, givensur, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:22 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0