我正在使用 SFSafariViewController 在我的应用程序中获取用户的 cookie。这是我的代码:
SFSafariViewController *safari = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:referrerUrl] entersReaderIfAvailable:NO];
safari.delegate = self;
safari.modalPresentationStyle = UIModalPresentationOverCurrentContext;
safari.view.alpha = 0.0;
safari.view.hidden = true;
[self dismissViewControllerAnimated:false completion:nil];
NSLog(@"[referrerService - StoreViewController] presenting safari VC");
[self presentViewController:safari animated:false completion:nil];
这在 iOS 9 上运行良好。但在 iOS 10 上,SF Controller 似乎不起作用(它还阻止了我当前的上下文——恰好是另一个 UIWebView)。
任何人都可以建议隐藏 SFSafariViewController 的替代方法?
最佳答案
更新后的答案:
Apple 在最新版本 review guidelines 中禁止使用这种 SafariViewController :
SafariViewContoller must be used to visibly present information to users; the controller may not be hidden or obscured by other views or layers. Additionally, an app may not use SafariViewController to track users without their knowledge and consent.
旧答案:
在 iOS 10 中,对呈现的 SFSafariViewController
有一些额外的要求:
1) 您的 View 不应隐藏,因此hidden
应设置为NO
2) alpha
的最小值为 0.05
3) 您需要使用 addChildViewController:
/didMoveToParentViewController:
手动添加 Controller (否则不会调用回调)。
4) UIApplication.keyWindow.frame
和 SFSafariViewController.view.frame
应该有非空交集(在适当的坐标空间中),这意味着:
safari View 大小应大于
CGSizeZero
您不能将 safari View 置于屏幕之外
但您可以在自己的 View 下隐藏 safari View
代码示例:
self.safariVC = [[SFSafariViewController alloc] initWithURL:referrerUrl];
self.safariVC.delegate = self;
self.safariVC.view.alpha = 0.05;
[self addChildViewController:self.safariVC];
self.safariVC.view.frame = CGRectMake(0.0, 0.0, 0.5, 0.5);
[self.view insertSubview:self.safariVC.view atIndex:0];
[self.safariVC didMoveToParentViewController:self];
此外,不要忘记在使用结束后正确删除 safariVC
:
[self.safariVC willMoveToParentViewController:nil];
[self.safariVC.view removeFromSuperview];
[self.safariVC removeFromParentViewController];
关于objective-c - 当 alpha 设置为 0 时,iOS10 SFSafariViewController 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39019352/