I'm using SFSafariViewController to grab user's cookie in my app. Here's is my code:
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];
This works well on iOS 9. but on iOS 10 it seems that the SF controller doesn't work (it also block my current context - which happens to be another UIWebView).
Anyone can suggest of an alternative way to hide a SFSafariViewController?
I was able to achieve this affect using invisible child view controller:
New info: Don't do this. The revised App Store guidelines prohibit this practice.
https://developer.apple.com/app-store/review/guidelines/
I'll leave this below for posterity: I call the following code from my app delegate's didFinishLaunchingWithOptions.
its possible to use this on swift 3 for xcode 8.3.2 becausa i get all i delegate anduse correctly , but i have this error
[12:05] 2017-04-25 12:05:03.680 pruebaslibrary[7476:136239] Warning: Attempt to present on whose view is not in the window hierarchy!
Updated answer:
Apple prohibits this kind of SafariViewController usage in last version of review guidelines:
Old answer:
In iOS 10 there are some additional requirements for presented
SFSafariViewController
:1) Your view should not be hidden, so
hidden
should be set toNO
2) The minimum value for
alpha
is0.05
3) You need to add controller manually with
addChildViewController:
/didMoveToParentViewController:
(callback's doesn't called otherwise).4)
UIApplication.keyWindow.frame
andSFSafariViewController.view.frame
should have non-empty intersection (in appropriate coordinate space), that means:safari view size should be greater than
CGSizeZero
you can't place safari view off the screen
but you can hide safari view under your own view
Code example:
Also, don't forget to remove
safariVC
properly after the end of the usage: