1

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.

Vemonus
  • 868
  • 1
  • 16
  • 28
Shital
  • 45
  • 1
  • 8

1 Answers1

2

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");
}];
hawkeyecoder
  • 571
  • 4
  • 10