I want to call javascript function from one of my view controller class,
here is my code snippet i have tried, but it is not working :(
Code in my ViewController
- (NSString *)MyMehtod{
JSContext *context = [[JSContext alloc] init];
JSValue *function = context[@"ProfilePicFunction"];
[context evaluateScript: [self loadJsFromFile]]; //crashes here EXC_BAD_ACESS
JSValue* result = [function callWithArguments:@[[documentsDirectory stringByAppendingString:@"/ProfilePic.png"]]];
NSLog(@"res = %@",result);
}
- (NSString *)loadJsFromFile
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"js"]; //path returns here as nil
NSString *jsScript = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; //jsScript returns here as nil
return jsScript;
}
Code in app.js file
function ProfilePicFunction(ProfilePicPath){
var d= new Date();
var userFullPath = ProfilePicPath+"?"+d.getTime();
$("#userImg").attr("src",userFullPath);
}
Location of app.js Please help and thanks in advance!!
Aucun commentaire:
Enregistrer un commentaire