0

I have simple code

NSURL *url = [NSURL URLWithString:@"https://en.wikipedia.org/wiki/Cat"];
if ([SFSafariViewController class] != nil) {
    SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:url];
    [self presentViewController:sfvc animated:YES completion:nil];
} else {
    [[UIApplication sharedApplication] openURL:url];
}

I've tested on iOS 9.3. When I first open url I can see the page in mobile mode.

enter image description here (Picture 1)

Next I click Desktop. And I can see this page (Picture 2)

enter image description here (Picture 2)

I restarted application and SFSafariViewController still opens page in Desktop mode (Picture 2). Can I force open the url in the mobile mode using SFSafariViewController and How Can I do this?

Kiryl Bielašeŭski
  • 2,663
  • 2
  • 28
  • 40

3 Answers3

1

The "Desktop" link in this context means the user will see what s/he would normally see when clicking on their Macintosh or PC. This is expected behavior.

If you suspend and then resume the application, especially when SFSafariViewController is visible to the user, the app will resume on the same page where it was left off, unless you tell it to re-open the original URL (which you can do by having your application delegate watch for applicationWillEnterForeground: and then force reload the view controller).

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
0

if it were working fine, then all you need to do is to click mobile view in wikipedia footer, otherwise rebuild your app and clean it, it will restore the default behavior

Abdoelrhman
  • 906
  • 8
  • 17
  • In common situation My application can use any url. And not every site has function mobile mode in the footer. Also I want to integrate SFSafariViewController in my Product application. Rebuilding and cleaning will not help me. – Kiryl Bielašeŭski Apr 22 '16 at 17:43
  • it will load the mobile version, here you yourself requested the desktop one, there's some answers who said that you'd add your request header as mobile, but i think that's unnecessary as it's the default behavior – Abdoelrhman Apr 23 '16 at 11:02
0

The final solution that I found, It's using specific links with a prefix (m.) that the server supports, It will force open the urls with the mobile mode:

NSURL *url = [NSURL URLWithString:@"https://en.m.wikipedia.org/wiki/Cat"];
Kiryl Bielašeŭski
  • 2,663
  • 2
  • 28
  • 40