Я хочу интегрировать. js в коде моей цели- c с помощью wkWebview.но я получаю ошибку ниже в моем коде.
Код
NSString *jsFile = @"jquery-1.7.2.min.js";
NSString *jsFilePath = [[NSBundle mainBundle] pathForResource:jsFile ofType:nil];
NSURL *jsURL = [NSURL fileURLWithPath:jsFilePath];
NSString *javascriptCode = [NSString stringWithContentsOfFile:jsURL.path encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:javascriptCode];
NSString *jsFile1 = @"default.js";
NSString *jsFilePath1 = [[NSBundle mainBundle] pathForResource:jsFile1 ofType:nil];
NSURL *jsURL1 = [NSURL fileURLWithPath:jsFilePath1];
NSString *javascriptCode1 = [NSString stringWithContentsOfFile:jsURL1.path encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:javascriptCode1];
@interface WKWebView(SynchronousEvaluateJavaScript)
- (NSString )stringByEvaluatingJavaScriptFromString:(NSString )script;
@end
@implementation WKWebView(SynchronousEvaluateJavaScript)
- (NSString )stringByEvaluatingJavaScriptFromString:(NSString )script
{
__block NSString *resultString = nil;
__block BOOL finished = NO;
[self evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
if (error == nil) {
if (result != nil) {
resultString = [NSString stringWithFormat:@"%@", result];
}
} else {
NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
}
finished = YES;
}];
while (!finished)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
return resultString;
}
@end
Ошибка Ошибка "JavaScript Выполнение вернуло результат неподдерживаемого типа"