以实现iOS11及以上获取共享cookie 和iOS11以下获取共享cookie
ios11以上SFAuthenticationSession来实现共享 ios11以下SFSafariViewController来实现共享
(SFAuthenticationSession是基于NSObject的所以更改不了其中的控件,至于权限弹框,是苹果防止窃取用户隐私的弹框,目前还没想到影藏方案)
SFAuthenticationSession实现方法
if(@available(iOS11.0, *)) {
self.authSession = [[SFAuthenticationSession alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.baidu.com"]] callbackURLScheme:nil completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) {
self.authSession=nil;
}];
[self.authSession start];
}
SFSafariViewController实现方法
#import<SafariServices/SafariServices.h>
<SFSafariViewControllerDelegate>//代理
SFSafariViewController *sf = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:@"http://t.www.17byh.com/test2.html"]];
[self presentViewController:sf animated:YES completion:nil];
//加载完成
- (void)safariViewController:(SFSafariViewController*)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully {
NSLog(@"加载完成");
// NSHTTPCookieStorage * storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
//
// NSArray * cookiesArray = storage.cookies;
// NSLog(@"cookiesArray == %@",cookiesArray);
}
SFSafariViewController代理方法
//点击左上角的done
- (void)safariViewControllerDidFinish:(SFSafariViewController*)controller {
NSLog(@"点击左上角的done");
// [self dismissViewControllerAnimated:YES completion:nil];
}
********有其他问题一起讨论********
网友评论