ios - Send javascript function to objective-C using JavascriptCore -
i'm trying send javascript function object objective-c via javascriptcore, leveraging jsexport protocol. have function declared in objective-c, conforming jsexport follows:
(class view) + (void) newwithfunc:(id)func { nslog(@" %@ ", func); } after declaring class, seek phone call function above javascript function object parameter
jsvalue *val; val = [context evaluatescript:@"var mufunc = function() { self.value = 10; };"]; val = [context evaluatescript:@"mufunc;"]; nslog(@" %@", val); //prints 'function() { self.value = 10; }', seems correct. val = [context evaluatescript:@"var view = view.newwithfunc(mufunc);"]; when lastly phone call made, parameter sent objective-c method of type 'nsdictionary', doesn't seem valuable if phone call function objective-c @ later point in time. possible javascriptcore?
please mark tayschrenn's answer correct. don't know how knew or it's documented, figured out trial , error:
- (void)newwithfunc: (jsvalue*)func { [func callwitharguments:@[]]; // invoke js func no params } declaring parameter (id)func apparently causes javascript-cocoa bridge convert nsdictionary (as noticed), rendering unusable callable jsvalue.
ios objective-c javascriptcore
No comments:
Post a Comment