objective-c - 当 alpha 设置为 0 时,iOS10 SFSafariViewController 不工作

标签 objective-c cookies ios10 sfsafariviewcontroller install-referrer

我正在使用 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.frameSFSafariViewController.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/

相关文章:

ios - 更改从我的 iMessage 扩展程序接收新消息时显示在锁屏上的推送通知消息

php - 限制每日访问

JavaScript Cookie 保存表单

cookies - 如何在 cfscript 中设置 cookie 的过期日期

ios - Swift 错误无法转换类型 '(AFHTTPRequestOperation?, AnyObject?) 的值 -> ()

ios - numberOfRowsInSection 导致无法识别的选择器崩溃

ios - 我如何使用 Paypal 进行拆分付款

iphone - NSFetchedResultsController 的 sectionNameKeyPath 不工作

ios - 如何在 Xib 文件中设置动画 Segue 样式,就像在 iOS 中的 StoryBoard Segue 样式一样?

ios - TodayWidget 构建正确但 com.apple.springboard 正在运行