以實現(xiàn)iOS11及以上獲取共享cookie? 和iOS11以下獲取共享cookie
ios11以上SFAuthenticationSession來實現(xiàn)共享? ios11以下SFSafariViewController來實現(xiàn)共享
(SFAuthenticationSession是基于NSObject的所以更改不了其中的控件,至于權(quán)限彈框,是蘋果防止竊取用戶隱私的彈框,目前還沒想到影藏方案)
SFAuthenticationSession實現(xiàn)方法
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實現(xiàn)方法
#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];
}
********有其他問題一起討論********