js-- (void)webViewDidFinishLoad:(UIWebView *)webView
{
JSContext *contentJS = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
__weak typeof(self)weakSelf =self;
contentJS[@"console"][@"log"] = ^(JSValue * msg) {
JSValue *jsValue= msg;
NSString *str = [jsValue toString];
NSLog(@"H5 log : %@", msg);
};
contentJS[@"console"][@"warn"] = ^(JSValue * msg) {
NSLog(@"H5 warn : %@", msg);
};
contentJS[@"console"][@"error"] = ^(JSValue * msg) {
NSLog(@"H5 error : %@", msg);
};
contentJS[@"Function"] = ^() {
NSArray *thisArr = [JSContext currentArguments];
for (JSValue *jsValue in thisArr) {
NSLog(@"=======%@",jsValue);
}
//
// //JSValue *this = [JSContext currentThis];
//
// //NSLog(@"this: %@",this);
//
NSLog(@"js调用oc---------The End-------");
};
NSLog(@"webViewDidFinishLoad");
}
pragma mark -- 获取cookie
-
(void)getCookie:(NSURL )url
{
NSHTTPCookieStoragecookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray *cachCookies = [cookieJar cookiesForURL:url];NSMutableString cookieString = [[NSMutableString alloc] init];
for (NSHTTPCookiecookiew in [cookieJar cookies]) {
[cookieString appendFormat:@"%@=%@;",cookiew.name,cookiew.value];
}
NSString *str=cookieString;
}
pragma mark -- 清楚cookie
-
(void)clearCookie:(NSURL *)url
{
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];//清除所有cookie
NSArray *cachCookies = [cookieStorage cookiesForURL:url];
for (int i = 0; i < [cachCookies count]; i++) {
NSHTTPCookie *cookie = (NSHTTPCookie *)[cachCookies objectAtIndex:i];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}