Search code examples
iosios9nsurlsfsafariviewcontroller

SFSafariViewController doesn't open url in mobile mode


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?


Solution

  • 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"];