SFSafariViewController在移动模式下无法打开网址

时间:2016-04-22 17:13:09

标签: ios ios9 nsurl sfsafariviewcontroller

我有简单的代码

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];
}

我已在iOS 9.3上测试过。当我第一次打开网址时,我可以在移动模式下看到该页面。

enter image description here (图1)

接下来,我点击桌面。我可以看到这个页面(图2)

enter image description here (图2)

我重新启动了应用程序,SFSafariViewController仍在桌面模式下打开页面(图2)。 我可以使用SFSafariViewController在移动模式下强制打开网址吗?我该怎么做?

3 个答案:

答案 0 :(得分:1)

此上下文中的“桌面”链接表示用户将看到他/她在单击Macintosh或PC时通常会看到的内容。这是预期行为。

如果你暂停然后恢复应用程序,特别是当SFSafariViewController对用户可见时,应用程序将在停止的同一页面上恢复,除非你告诉它重新打开原始URL(你可以通过让您的应用程序委托监视applicationWillEnterForeground:然后强制重新加载视图控制器来实现。

答案 1 :(得分:0)

如果它工作正常,那么你需要做的就是点击维基百科页脚中的移动视图,否则重建你的应用并清理它,它将恢复默认行为

答案 2 :(得分:0)

我找到的最终解决方案是,它使用服务器支持的带有前缀(m。)的特定链接,它将强制以移动模式打开网址:

NSURL *url = [NSURL URLWithString:@"https://en.m.wikipedia.org/wiki/Cat"];
相关问题