gpt4 book ai didi

ios - iOS 11/Xcode 9.0 中的 SFSafariViewController 空白

转载 作者:可可西里 更新时间:2023-11-01 17:12:55 24 4
gpt4 key购买 nike

我有一个 SFSafariViewController,通过单击 UIActionSheet 中的按钮打开。它一直运行良好,并且在除 iOS 11 之外的所有 iOS 版本上仍然运行良好。他们是否对 iOS 11 或 Xcode 9.0 中的 SFSafariViewController 进行了更改,可能导致此问题?

更新 - 似乎是 Xcode 9.0 导致了这个问题。我试过在不同的 iOS 版本上运行它,它们似乎都出现了这个问题。当我使用 Xcode 8.3.3 运行它时,它曾经工作正常,但我不再拥有它了:(

这是代码 -

- (void)presentWebView:(NSString *)url {
url = [url stringByReplacingOccurrencesOfString:@" " withString:@"+"];
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *URL = [NSURL URLWithString:url];

if (URL) {
if ([SFSafariViewController class] != nil) {
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL];
sfvc.delegate = self;
[self.tabBarController presentViewController:sfvc animated:YES completion:nil];
} else {
if (![[UIApplication sharedApplication] openURL:URL]) {
NSLog(@"%@%@",@"Failed to open url:",[url description]);
}
}
} else {
// will have a nice alert displaying soon.
}

最佳答案

我已经设法在我的代码中解决了这个问题。我希望这可以帮助其他有类似问题的人。

我遇到了与这里描述的完全相同的问题。我尝试了上面的一切,不幸的是没有任何效果。

在我的应用程序中有不同的窗口。解决方法是确保将显示 SFSafariViewController 的窗口在显示之前是“关键”。例如:

class MyViewController: UIViewcontroller {
func showSafariViewController() {
// imagine we have 2 windows, one for 'normal' content (key window) and one for 'other' content. lets say we're showing the 'other' content window, and have hidden the 'normal' window. you can see the 'other' content window in the app, but it won't be the key window!
let window = // get the 'other' content window

// make sure we make it the key window before presenting safari
window.makeKey()

// now present safari and celebrate victory by triumphantly slurping on your hot black coffee
let mySafariViewController = SFSafariViewController(...)
self.present(mySafariViewController ...)
}
}

我怀疑 Apple 正在搜索 UIApplication.shared.keyWindow 窗口中的 SFSafariViewController 实例。也许他们正在从其他地方添加 subview 。在文档中它指出 用户的事件和与 SFSafariViewController 的交互对您的应用程序不可见,因此可能是该错误与增加的安全级别有关 https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller

关于ios - iOS 11/Xcode 9.0 中的 SFSafariViewController 空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46439142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com