1

我在 javascript 文件中有某些验证功能。我想在我的 IOS 应用程序中使用它们。

NSString *path = [[NSBundle mainBundle] pathForResource:@"validate" ofType:@"js"];

NSError* error;

NSString* validate = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];

我在 validate.js 中有一个函数 keyDetails()

我如何创建该函数的实例并调用它。

4

1 回答 1

1

你会这样做:

NSString *path = [[NSBundle mainBundle] pathForResource:@"validate" ofType:@"js"];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
NSString *result = [webView stringByEvaluatingJavaScriptFromString:@"keyDetails()"];

的文档stringByEvaluatingJavaScriptFromString这里

于 2013-11-11T14:18:28.160 回答