2

There is a button on ViewController A, that when pressed should take me to ViewControllerB which has a UIWebView. That web view should load the desktop version of a website.

These are the steps I take:

  1. ViewController A - Touch button

  2. ViewController B - The UIWebView loads the mobile version of the website instead of desktop version.

  3. NavigationController - Touch the back button -> takes us back to ViewController A

  4. ViewController A - Touch the button again

  5. ViewController B - UIWebView loads the desktop version as desired.

The first time (Step 2), the UIWebView does not load the correct URL and second time (Step 5) it loads the correct URL.

VIEW A-

-(IBAction)ButtonPressed:(id)sender{

HomeAppDelegate *myDelegate = (HomeAppDelegate *)[[UIApplication sharedApplication]delegate];

NSString *titleCaption;WebPageViewController *chosenViewController = [[WebPageViewController alloc] initWithNibName:@"WebPageViewController" bundle:nil];

titleCaption = @"Web PAGE";

chosenViewController.url = [NSURL URLWithString:@"http://www.mydesktopwebsite.com"];

[self.navigationController pushViewController:chosenViewController animated:YES];

myDelegate.navBar.topItem.title  = titleCaption;

[chosenViewController release];
}

VIEW B - WebPageViewController.h

@property (retain, nonatomic) IBOutlet UIWebView *WebView;
@property (retain, nonatomic) NSURL *url;

WebPageViewController.m

@synthesize url;

- (void)viewDidLoad{
[super viewDidLoad];

[self.WebView loadRequest:[NSURLRequest requestWithURL:self.url]];}

(Edit note from jcesar: You edited my answer, but I think you wanted to edit your question, so I add the code you put in my answer)

I was using following code which obviously wrong.

NSDictionary *dictionary = @{ @"UserAgent" : @"Safari iOS 5.1 - iPhone"}; 
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
Nitya
  • 849
  • 1
  • 11
  • 25
  • It would probably help if you updated your question with the relevant code showing how you setup and load the `UIWebView`. – rmaddy Nov 18 '13 at 17:23

1 Answers1

10

It deppends on the web, but you can try to change the user agent to make the server think it's a desktop browser

To change the "UserAgent" default value run this code when your app starts:

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];  
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • Thanks @jcesarmobile but how to change this vise versa like switch **ON** & **OFF** please tell me if you know.. if it is on than desktop version and if switch is off than mobile version using **Defaults** not manipulate URL request adding user agent – JAY RAPARKA Aug 30 '17 at 10:38
  • This set the user agent to whatever you put, but if you change it after the app is running it won't take effect. To do it dynamically you have to do it on url load time like explained here https://stackoverflow.com/questions/36889970/change-user-agent – jcesarmobile Aug 30 '17 at 11:06
  • Thanks @jcesarmobile for your instant replay. I got the user-agent for mobile version: that is **Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3** – JAY RAPARKA Aug 30 '17 at 13:01