web端调用iOS原生

OC端

- (void)loadWebPageWithString:(NSString*)urlString
{
  NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
  [self setUserAgent];
  [_webView loadRequest:request];

  JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];


  context[@"test"] = ^() {
    NSArray *args = [JSContext currentArguments];
     for (JSValue *jsVal in args) {  
            NSLog(@"%@", jsVal); 
        }        


}

web端

  
           
  
     
      
    
  
  

你可能感兴趣的:(web端调用iOS原生)