iOS9 利用SFSafariViewController实现不

2016-08-04  本文已影响363人  LeLeBa

#import<SafariServices/SFSafariViewController.h>;

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {    

            [super viewDidLoad];               

 }

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {        

           SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"url"]];    

           safariVC.delegate = self;    

           safariVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;                  

           safariVC.view.alpha = 0.0;    

           [self presentViewController:safariVC animated:NO completion:^{}];

}

- (void)didReceiveMemoryWarning {    

            [super didReceiveMemoryWarning];    

            // Dispose of any resources that can be recreated.

}

- (void)safariViewController:(SFSafariViewController *)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully {

             [self dismissViewControllerAnimated:NO completion:^{}];

}

备注:种cookie的时候,加上超时 expires 值,我调试的时候,开始没设 expires 值,没有读到cookie;

如果设了expires 还是没读到cookie,参考:http://stackoverflow.com/questions/36203617/why-is-sfsafariwebviewcontroller-not-sharing-cookies-with-safari-properly

里面有人提到:

A user on the Apple Dev Forums suggested that it might only work for "persisted cookies" not "session cookies". I wasn't setting an expiry date on my cookies. I changed that by getting a time in the future:

const expireTime = new Date(Date.now() + 1000 * 60 * 60 * 24).toGMTString();

And then setting it in the header:

"Set-Cookie":`query=${uri.query}; path=/; expires=${expireTime}`

And now the cookie value appears in SFSafariViewController.

有了这个,可以做的事情就很多了,产品的同学发挥自己的想象力吧。

我们产品想用这个跟踪通过广告下载我们App的用户。

上一篇 下一篇

猜你喜欢

热点阅读