我在javascript文件中有一些验证功能。我想在我的IOS应用程序中使用它们。
NSString *path = [[NSBundle mainBundle] pathForResource:@"validate" ofType:@"js"];
NSError* error;
NSString* validate = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
我在validate.js
中有一个功能keyDetails()如何创建该功能的实例并调用它。
答案 0 :(得分:1)
这就是你要做的:
NSString *path = [[NSBundle mainBundle] pathForResource:@"validate" ofType:@"js"];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
NSString *result = [webView stringByEvaluatingJavaScriptFromString:@"keyDetails()"];
stringByEvaluatingJavaScriptFromString
的文档是here。