我在uiactionsheet内的一个按钮时单击一个sfsafariviewController。除iOS 11以外,它的运行良好,并且在iOS的所有版本上仍处于正常状态。在iOS 11中或Xcode 9.0中的SFSafariviewController是否有任何更改的东西可能引起了此问题?
Update - 因此,似乎正在引起此问题的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 ...)
}
}
我怀疑苹果正在窗口UIApplication.shared.keyWindow
中搜索SFSafariViewController
实例。也许他们从其他地方添加了一个孩子的视野。在文档中它指出了The user's activity and interaction with SFSafariViewController are not visible to your app
,因此也许是错误与添加的安全级别有关https://developer.apple.com/documentation/safariservices/sfsafarivariviewcontroller
我试图使用延迟来进行控制器加载。
方法1 。使用延迟。
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
let controller = SFSafariViewController(url: url)
controller.modalPresentationStyle = .overFullScreen
self.present(controller, animated: true, completion: nil)
controller.delegate = self
}
方法2。加载视图。
let controller = SFSafariViewController(url: url)
let _ = controller.view
controller.modalPresentationStyle = .overFullScreen
self.present(controller, animated: true, completion: nil)
controller.delegate = self
与https://openradar.appspot.com/29108332
非常相似要修复它,您可以禁用视图的懒惰加载:
SFSafariViewController *viewController = [[SFSafariViewController alloc] init...];
(void)viewController.view;
...
[controller presentViewController:viewController animated:YES completion:nil];
update
事实证明,旧答案不起作用,因为我放了断点,所以它起作用了。如果我添加了线程睡眠,似乎在XCode9中起作用,但这不是最好的解决方案。有人有另一个更好的解决方案吗?
SFSafariViewController *sfcontroller = [[SFSafariViewController alloc] initWithURL:url];
if (@available(iOS 11.0, *)) {
[NSThread sleepForTimeInterval:0.5f];
}
sfcontroller.delegate = self;
[controller presentViewController:sfcontroller animated:NO completion:nil];
旧答案
我有与Genaks相同的问题,并与SfviewController一起修补。
似乎对我有用
SFSafariViewController *sfcontroller = [[SFSafariViewController alloc] initWithURL:url];
if (@available(iOS 11.0, *)) {
SFSafariViewControllerConfiguration *config = [[SFSafariViewControllerConfiguration alloc] init];
config.barCollapsingEnabled = NO;
sfcontroller = [[SFSafariViewController alloc] initWithURL:url configuration: config];
} else {
// Fallback on earlier versions
}
sfcontroller.delegate = self;
[controller presentViewController:sfcontroller animated:YES completion:nil];
在iOS 11中,他们引入了sfsafariviewControllerConfiguration,默认情况下,BarCollapsingEnabled是正确的,似乎是造成我的空白Safariview的一种。希望这也解决了您的
我们遇到了这个问题:我们的URL是https://our-side.com/index.html
(将重定向到/account
路由的角站点)。当我们删除index.html
时,SFSafariViewController
正确加载了!
迄今为止对我有用的唯一事情就是以以下方式使SafariviewController成为rootviewController -
((XYZAppDelegate *)[UIApplication sharedApplication].delegate).window.rootViewController = self.svc;
[((XYZAppDelegate *)[UIApplication sharedApplication].delegate).window makeKeyAndVisible];