I am trying to insert a small webview (320x480) inside my iPad application to simulate a small “iPhone screen” displaying a mobile twitter. But every time uiwebview receives NSUrlRequest for downloading http://mobile.twitter.com , my application automatically breaks off the screen and iOS opens Twitter for iPad.
Is there any way to change this behavior?
That's what I'm doing:
UIWebView *viewDoTwitter = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.bounds.size.height)]; viewDoTwitter.autoresizingMask = UIViewAutoresizingFlexibleHeight; viewDoTwitter.scalesPageToFit = YES; [rootView insertSubview:viewDoTwitter atIndex:0]; [viewDoTwitter loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mobile.twitter.com"]]];
Edition:
OK, I found a solution, here: http://www.mphweb.com/en/blog/easily-set-user-agent-uiwebview
UIWebView *viewDoTwitter = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.bounds.size.height)]; viewDoTwitter.autoresizingMask = UIViewAutoresizingFlexibleHeight; viewDoTwitter.scalesPageToFit = YES; NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", @"UserAgent", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary]; [rootView insertSubview:viewDoTwitter atIndex:0]; [viewDoTwitter loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.twitter.com"]]];
But now before a new problem: mobile.twitter.com insists on adapting to the size of the iPad screen instead of the specified width of 320 pixels.
source share