欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js &cookie

程序员文章站 2022-07-13 12:29:06
...

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
    {
    NSHTTPCookieStorage
    cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *cachCookies = [cookieJar cookiesForURL:url];

    NSMutableString cookieString = [[NSMutableString alloc] init];
    for (NSHTTPCookie
    cookiew 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];
    }
    }

上一篇: Solaris 10 上网

下一篇: js cookie