我只想从 cookie 中获取访问令牌,在 if 条件下我想比较 cookie domain 和 given URL
。我正在尝试使用以下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [[NSURL alloc] initWithString:websiteUrl];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
- (NSString*)getTokenFromCookie {
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
NSLog(@"%@",cookie);
//Here to compare cookie domain and above given URL
if ([[cookie domain] isEqualToString:domain]) {
if ([[cookie name] isEqualToString:@"oauth_token"]) {
return [cookie value];
}
}
}
return nil;
}