Reputation: 11
SFSafariViewController allows a webpage to access cookie stored in Safari. I would like to perform some background task with SFSafariViewController to utilize the cookie. However I do not want the user to see the SFSafariViewController.
Is there a way to hide SFSafariViewController and allow user to touch the screen when SFSafariViewController is presented?
Upvotes: 1
Views: 1313
Reputation: 21881
Don't do this if you're planning to submit to the App Store.
From https://developer.apple.com/app-store/review/guidelines/:
5.1.1 (iv) 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.
If you need to access cookies, use WKWebView instead. See Getting all cookies from WKWebView. These cookies aren't shared with Safari, though.
Upvotes: 2
Reputation: 91
Class SFSafariViewControllerClass = NSClassFromString(@"SFSafariViewController");
if (SFSafariViewControllerClass) {
id safController = [[SFSafariViewControllerClass alloc] initWithURL:[NSURL URLWithString:urlString]];
UIViewController *windowRootController = [[UIViewController alloc] init];
self.secondWindow = [[UIWindow alloc] initWithFrame:CGRectZero];
self.secondWindow.rootViewController = windowRootController;
[self.secondWindow makeKeyAndVisible];
[self.secondWindow setAlpha:0];
[windowRootController presentViewController:safController animated:YES completion:^{
[self.secondWindow.rootViewController dismissViewControllerAnimated:NO completion:NULL];
}];
}
you can use the code to hide the SFSafariViewControllerClass
Upvotes: 2