Resolved UIWebView and Safari renders differently

Discussion in 'iOS Programming' started by macsrcool1234, Jan 14, 2013.

  1. macsrcool1234, Jan 14, 2013
    Last edited: Jan 14, 2013

    macsrcool1234 macrumors 65816

    Joined:
    Oct 7, 2010
    #1
    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)
    [​IMG]



    And finally, how it looks inside of `UIWebView` (incorrectly)
    [​IMG]


    I am completely clueless as to what would cause this behavior.
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    You uploaded the same photo twice. I think you're missing the safari picture.
     
  3. macsrcool1234 thread starter macrumors 65816

    Joined:
    Oct 7, 2010
    #3
    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.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    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.
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    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.
     

Share This Page