Javascript file not loading, and stringByEvaluatingJavaScriptFromString also not executing?

I have an application in which I download an html file from the server and show it in uiwebview,

NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
NSString *documentsDirectory = [paths firstObject];
NSString *path = [documentsDirectory stringByAppendingPathComponent:[dictionary valueForKey:@"htmlfilename"]];

NSError *err;
NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&err];

[self.webview loadHTMLString:html baseURL:[NSURL fileURLWithPath:path]];

Like this, after that in DidfinishloadI upload one JS file which is added to my application package like this

NSString *javaScript=[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"foo" ofType:@"js"] encoding:NSUTF8StringEncoding error:nil];

[webview stringByEvaluatingJavaScriptFromString:javaScript];

After that, when I press the button, I call stringByEvaluatingJavaScriptFromString, but it does not work. Even the javascript file itself does not load. Can anyone direct me to this?

+4
source share
1 answer

JavaScriptCore Framework JavaScript Native iOS. WebKit JavaScript Engine. MAC, iOS / objective-c javascript. .

https://www.raywenderlich.com/124075/javascriptcore-tutorial

, . , .

!

0

Source: https://habr.com/ru/post/1675238/


All Articles