首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SFSafariViewController 11/Xcode 9.0中的iOS空白

SFSafariViewController 11/Xcode 9.0中的iOS空白
EN

Stack Overflow用户
提问于 2017-09-27 03:44:49
回答 5查看 6K关注 0票数 4

我有一个SFSafariViewController打开在点击一个按钮在一个UIActionSheet。除了iOS 11之外,它一直运行良好,而且仍然运行良好。在iOS 11或Xcode 9.0中的SFSafariViewController方面,是否有什么改变可能导致了这个问题?

更新-所以它的Xcode 9.0似乎是造成这个问题的原因。我尝试过在不同的iOS版本上运行它,所有这些版本似乎都给出了这个问题。当我使用Xcode 8.3.3运行它时,它过去运行得很好,这是我再也没有的东西了:

这是密码-

代码语言:javascript
运行
复制
- (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.
}

}

EN

回答 5

Stack Overflow用户

发布于 2019-07-31 11:22:12

我试着用延迟来做它,并使控制器loading.Both的视图为我工作。

方法1。使用延迟。

代码语言:javascript
运行
复制
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.加载视图。

代码语言:javascript
运行
复制
      let controller = SFSafariViewController(url: url)
      let _ = controller.view
      controller.modalPresentationStyle = .overFullScreen
      self.present(controller, animated: true, completion: nil)
      controller.delegate = self
票数 5
EN

Stack Overflow用户

发布于 2017-09-27 09:22:31

非常类似于https://openradar.appspot.com/29108332

要修复它,可以禁用视图的延迟加载:

代码语言:javascript
运行
复制
SFSafariViewController *viewController = [[SFSafariViewController alloc] init...];
(void)viewController.view;
...
[controller presentViewController:viewController animated:YES completion:nil];
票数 3
EN

Stack Overflow用户

发布于 2017-09-27 19:35:19

更新

原来原来的答案行不通,只是因为我放了断点才起作用。如果我添加了线程睡眠,它似乎在XCode9中有效,但这不是最好的解决方案。还有其他更好的解决方案吗?

代码语言:javascript
运行
复制
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];

旧答案

我有同样的问题,与天才和修补周围的SFViewController。

看起来这段代码适合我

代码语言:javascript
运行
复制
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的原因。希望这也能解决你的问题

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46439142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档