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 04-08-2011, 02:46 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 60
nathanl1192 is on a distinguished road
Default Load iPhone web pages in iPad app.

Hi Guys!

I have an iPad app in development, which is a web browser, however I want the browser to automatically load the iPhone (not iPad) version of sites entered in through the URL or search box.

Anyone know how?

Thanks,

Nathan
nathanl1192 is offline   Reply With Quote
Old 04-08-2011, 02:56 PM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you need to change user agent, try as explained here
cocoa touch - Change User Agent in UIWebView (iPhone SDK) - Stack Overflow
__________________
dany_dev is offline   Reply With Quote
Old 04-08-2011, 03:02 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 60
nathanl1192 is on a distinguished road
Question Still Confused - Sorry!

Quote:
Originally Posted by dany_dev View Post
you need to change user agent, try as explained here
cocoa touch - Change User Agent in UIWebView (iPhone SDK) - Stack Overflow
Thanks, but I am still confused. I do not know where to put the code, how to implement it... or even what part of the User Agent to use. Can anyone break this down into simple steps for me! Thanks.

Nathan
nathanl1192 is offline   Reply With Quote
Old 04-08-2011, 03:55 PM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

put in didLoad of your viewController that contain uiwebview

myWebview.delegate = self;

where myWebview is your webview.

now add this method

Code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)req navigationType:(UIWebViewNavigationType)navigationType {
    NSMutableURLRequest *request = (NSMutableURLRequest *)req;

    if ([request respondsToSelector:@selector(setValue:forHTTPHeaderField:)]) {
        [request setValue:[NSString stringWithFormat:@"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"] forHTTPHeaderField:@"User_Agent"];
    }
    return YES; 
}
now when loading some page with that uiwebview, you should see the iphone version.
__________________
dany_dev is offline   Reply With Quote
Reply

Bookmarks

Tags
format, ipad, iphone, safari, web browser

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: 360
13 members and 347 guests
dansparrow, dre, ilmman, LezB44, michelle, Nobbsy, Objective Zero, samdanielblr, Sami Gh, shagor012, sledzeppelin, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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