Nit*_*tya 2 iphone uiwebview ios
ViewController A上有一个按钮,按下时应该带我到ViewControllerB,它有一个UIWebView.该Web视图应加载网站的桌面版本.
这些是我采取的步骤:
ViewController A - 触摸按钮
ViewController B - UIWebView加载网站的移动版本而不是桌面版本.
NavigationController - 触摸后退按钮 - >将我们带回ViewController A.
ViewController A - 再次触摸按钮
ViewController B - UIWebView根据需要加载桌面版本.
第一次(步骤2),UIWebView没有加载正确的URL,第二次(步骤5)它加载正确的URL.
查看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];
}
Run Code Online (Sandbox Code Playgroud)
视图B - WebPageViewController.h
@property (retain, nonatomic) IBOutlet UIWebView *WebView;
@property (retain, nonatomic) NSURL *url;
Run Code Online (Sandbox Code Playgroud)
WebPageViewController.m
@synthesize url;
- (void)viewDidLoad{
[super viewDidLoad];
[self.WebView loadRequest:[NSURLRequest requestWithURL:self.url]];}
Run Code Online (Sandbox Code Playgroud)
(编辑jcesar的注释:你编辑了我的答案,但我想你想编辑你的问题,所以我添加了你在答案中输入的代码)
我使用的代码显然是错误的.
NSDictionary *dictionary = @{ @"UserAgent" : @"Safari iOS 5.1 - iPhone"};
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
Run Code Online (Sandbox Code Playgroud)
jce*_*ile 10
它取决于网络,但您可以尝试更改用户代理,使服务器认为它是桌面浏览器
要更改"UserAgent"默认值,请在应用启动时运行此代码:
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];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3196 次 |
| 最近记录: |