I am currently trying to use:
NSString* arg = [NSString stringWithFormat:@"ReadiumSDK.reader.openSpineItemElementCfi(%@,%@,)", val1,val2];
[self executeJavaScript:arg completionHandler:nil];
but this throws an error.
I am currently trying to use:
NSString* arg = [NSString stringWithFormat:@"ReadiumSDK.reader.openSpineItemElementCfi(%@,%@,)", val1,val2];
[self executeJavaScript:arg completionHandler:nil];
but this throws an error.
I pass parameters into javascript functions all the time from a WkWebView:
One problem may be that your parameters need to be inside single quotes and you have an extra , at the end: "ReadiumSDK.reader.openSpineItemElementCfi('%@','%@')"
The key is calling the function the exact same way you would in a developer console in a browser:
Sample below in Chrome's developer tools I would type: SomeFunction('stringParameter')
NSString *someParameter = @"stringParameter";
NSString *javascript = [NSString stringWithFormat:@"SomeFunction('%@')", someParameter];
[wkWebView evaluateJavaScript:javascript completionHandler:^(NSString *result, NSError *error) {
if(error != nil) {
NSLog(@"SomeFunction Error: %@",error);
return;
}
NSLog(@" SomeFunction Success");
}];