2019独角兽企业重金招聘Python工程师标准>>>
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// [webView stringByEvaluatingJavascriptFromString:@"myFunction();"];NSHTTPCOOKIEStorage *sharedHTTPCOOKIEStorage = [NSHTTPCOOKIEStorage sharedHTTPCOOKIEStorage];NSArray *COOKIEs = [sharedHTTPCOOKIEStorage COOKIEsForURL:request.URL];NSEnumerator *enumerator = [COOKIEs objectEnumerator];NSHTTPCOOKIE *COOKIE;while (COOKIE = [enumerator nextObject]) {NSLog(@"COOKIE{name: %@, value: %@}", [COOKIE name], [COOKIE value]);}
}
Apple官方参考文档:https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSHTTPCOOKIEStorage_Class/index.html
题外话:
关于ios如何与webview同步登陆状态
1.之前的提议为:在webView页面回调APP端的登陆流程;
2.但有觉得:还得各走各的接口更好,如果在webview里需要登陆就直接走webview的登陆,分开处理更恰当。*APP打开webview的时候,携带登录状态的token;
*JS请求APP登录页面的时候,携带回调地址;
*APP登录成功后判断是否有回调地址,如果有则跳转到webview;
*JS通过APP打开webview时携带的token在请求接口时会做登录状态判断;