SFSafariViewController无法在移动模式下打开URL

问题描述 投票:0回答:3

我有简单的代码

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在移动模式下强制打开网址吗?我该怎么做?

ios ios9 nsurl sfsafariviewcontroller
3个回答
1
投票

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

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


0
投票

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


0
投票

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

NSURL *url = [NSURL URLWithString:@"https://en.m.wikipedia.org/wiki/Cat"];
© www.soinside.com 2019 - 2024. All rights reserved.