'EXEC_BAD_ACCESS error when using WebViewJavascriptBridge

I'm a very new iOS developer (I only started a few days ago), and I'm trying to utilize the WebViewJavascriptBridge class with a UIWebView that I've got on my Storyboard. Whenever I try to use it, I get an EXEC_BAD_ACCESS error.

The trouble lines seem to be:

- (void)viewDidLoad
{
    [super viewDidLoad];

    WebViewJavascriptBridge* bridge = [WebViewJavascriptBridge bridgeForWebView:webView handler:^(id data, WVJBResponseCallback responseCallback) {
        NSLog(@"Received message from javascript: %@", data);
        responseCallback(@"Right back atcha");
    }];

    webView.scrollView.bounces = NO;

    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    NSString *path = [[NSBundle mainBundle] bundlePath];
    path = [NSString stringWithFormat:@"%@/%s", path, "htdocs/index.html"];
    NSURL *URL = [NSURL fileURLWithPath:path];

    [webView loadRequest:[[NSURLRequest alloc] initWithURL:URL]];
}

To be exact, the last line. If I don't make that request, I don't get the error. I've tried it with a UIWebView created just in Objective-C, and still gotten the error, although maybe I did it wrong.

Any suggestions?

EDIT:

Method for storing webView is this code + reference outlet.

@interface mcViewController : UIViewController
    {
        IBOutlet UIWebView *webView;
    }
@end


Solution 1:[1]

Maybe you should change to use this library.

SDBridgeOC

 self.bridge.consolePipeBlock = ^(id  _Nonnull water) {
        NSLog(@"Next line is javascript console.log------>>>>");
        NSLog(@"%@",water);
    };

This can easy to get javascript console.log.

Also have Swift language Version.

SDBridgeSwift

bridge.consolePipeClosure = { water in
         guard let jsConsoleLog = water else {
             print("Javascript console.log give native is nil!")
              return
         }
         print("Next line is Javascript console.log----->>>>>>>")
         print(jsConsoleLog)
      }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 housenkui