Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macsrcool1234

Suspended
Original poster
Oct 7, 2010
1,551
2,130
UPDATE: The problem was solved by changing the user agent of Safari, following the instructions here:

http://www.mphweb.com/en/blog/easily-set-user-agent-uiwebview

I have a UIWebView which is adapted to a mobile style of a forum I have. In Safari, it looks and works great.

However, inside my UIWebView there is a major problem.

When quoting or editing a post, HTML is displayed inside of `BBcode`. Furthermore, posting code results in ignored line breaks. This problem will render my app completely unusable.


The webview is loaded like this:

PHP:
      //display the webview
        NSString *fullURL = @"http://www.mysite.com";
        NSURL *url = [NSURL URLWithString:fullURL];
        NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
        [_webTest loadRequest:requestObj];

This is how it looks inside of mobile Safari (correctly)
dYX6v.png




And finally, how it looks inside of `UIWebView` (incorrectly)
WPOpt.png



I am completely clueless as to what would cause this behavior.
 
Last edited:
You uploaded the same photo twice. I think you're missing the safari picture.

Ah sorry, I actually fixed the problem. Changing the user agent to mobile safari fixed it.

I've updated the original post and set it to resolved.

But if anybody wants to answer WHY changing the user agent fixed the issue, that would be great because I still don't understand that. Doesn't the user agent simply identify the type of browser? Why would changing it alter the way it's rendered? Thanks.
 
But if anybody wants to answer WHY changing the user agent fixed the issue, that would be great because I still don't understand that. Doesn't the user agent simply identify the type of browser? Why would changing it alter the way it's rendered? Thanks.

Maybe the server is sending different content based on the user agent string. That's a pretty common practice.

You can tell the desktop versions of Safari to use various user agent strings.
Safari > Preferences > Advanced > checkbox: Show Develop menu in menu bar.
Then: Develop menu > User Agent submenu

You should probably look at the actual data being sent over the wire if you want to find out exactly what's happening.
 
This is probably a bug on your server. It doesn't recognize the user agent that is used by UIWebView but it does recognize the user agent used by Safari.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.