windowScriptObject method not found on Objective-C code

心不动则不痛 提交于 2019-12-24 00:56:50

问题


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:


windowScriptObject seems not to be available on iOS. Reference

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



来源:https://stackoverflow.com/questions/8701835/windowscriptobject-method-not-found-on-objective-c-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!