2017-09-27 80 views
0

我在UIActionSheet内点击按钮一开SFSafariViewController。它一直在正常工作,并且在iOS 11以外的所有iOS版本上仍然正常工作。有没有更改过iOS 11或Xcode 9.0中可能导致此问题的SFSafariViewController?SFSafariViewController空白iOS的11/9.0的Xcode

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. 
} 

}

+1

你能证明你试过代码什么的,ios11已经修改 –

+0

@ Anbu.Karthik添加的代码 – genaks

回答

0

非常相似,https://openradar.appspot.com/29108332

要修复它,你可以禁用的观点的延迟加载:

SFSafariViewController *viewController = [[SFSafariViewController alloc] init...]; 
(void)viewController.view; 
... 
[controller presentViewController:viewController animated:YES completion:nil]; 
+0

我不工作 – genaks

+0

顺便说一句 - (void)viewController.view; - 做? – genaks

+0

这导致视图加载:[“如果您访问此属性,其值为零,视图控制器自动调用 loadView() 方法并返回结果视图。”](https://developer.apple .com/documentation/uikit/uiviewcontroller/1621460-view) –

0

更新

原来的答案并没有工作,它只是因为我把断点工作。如果我添加了一个线程睡眠似乎它在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之一。希望这可以解决你太

+0

工程但是像你说的不是一个好的解决方案。顺便说一下0.5的神奇之处,因为我试图减少它,它不起作用。 – genaks

+1

工作一次后,这也停止了工作。 SafariViewController仍然是空白的 – genaks

0

到目前为止,我是让SafariViewController的RootViewController的以下列方式已经工作的唯一的事 -

((XYZAppDelegate *)[UIApplication sharedApplication].delegate).window.rootViewController = self.svc; 
    [((XYZAppDelegate *)[UIApplication sharedApplication].delegate).window makeKeyAndVisible]; 
1

我已经成功在我的代码来解决这个问题。我希望这可以帮助其他有类似问题的人。

我有完全相同的问题,因为这里描述。我尝试了以上的一切,不幸的是没有工作

在我的应用程序中有不同的窗口。解决方法是确保在展示之前显示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/sfsafariviewcontroller

+0

这解决了我的问题!谢谢! PS:你可以很容易地通过使用'UIApplication.shared.windows [0]'获得根窗口(也许这会帮助某人) –