windowScriptObject method not found on Objective-C

2019-07-19 16:54发布

I have an UIWebView with my application and want to call Objective-C method from JavaScript. All documentation and tutorial that I found, I see is just uses the windowScriptObject method, but in my code Xcode says that webView dont have instance method -windowScriptObject.

What's wrong?

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

    NSString *indexPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"];
    NSURL *url = [NSURL fileURLWithPath:indexPath];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];

    [self.view addSubview:webView];

    id win = [webView windowScriptObject]; // In this line, Xcode alert 'Instance method "-windowScriptObject" not found'
    [win setValue:@"yes" forKey:@"isExtended"];
}

1条回答
ゆ 、 Hurt°
2楼-- · 2019-07-19 17:15

windowScriptObject seems not to be available on iOS. Reference

Also, check similar question: how to use windowScriptObject on the iPhone?

查看更多
登录 后发表回答