作者:苏打c | 来源:互联网 | 2023-01-16 15:51
单击UIActionSheet内的按钮,我有一个SFSafariViewController打开.它已经工作正常,并且在除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.
}
}
1> larromba..:
我已经设法在我的代码中修复此问题.我希望这可以帮助其他有类似问题的人.
我有与此处描述的完全相同的问题.我尝试了以上所有内容,但遗憾的是没有任
在我的应用程序中有不同的窗口.修复是为了确保在显示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正在SFSafariViewController
窗口中搜索一个实例UIApplication.shared.keyWindow
.也许他们正在从其他地方添加一个儿童视图.在它所述的文档中The user's activity and interaction with SFSafariViewController are not visible to your app
,所以也许这个bug与增加的安全级别有关https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller