使用 UIWebview 从 Javascript 调用 Objective-C 方法类?
我的要求是:我需要初始化一个特定的objective-c类并使用UIWebview从javscript调用其方法,如下所示:
我有一个名为“Calculator”的objective-c类,它具有以下方法
@interface Calculator : NSObject {
}
@property (nonatomic, retain) start;
@property (nonatomic, retain) add:(NSInteger) a with:(NSInteger) b;
@property (nonatomic, retain) subract:(NSInteger) a by:(NSInteger) b;;
@end;
我有一个UIWebview,其中我我正在用 JS 加载 HTML。在这里,我有一个 JS 脚本函数,如
function callNativeClass() {
window.calc.start;
}
“calc”是类的实例或命名空间。我需要从 JS 调用 start 方法。
你能告诉我,是否有任何选项可以像 PhoneGap 一样调用本机 Objective-C 类?
My requirement is: I need to initialize a specific objective-c class and call its method from javscript using UIWebview like below eg:
I have an objective-c class called "Calculator" which has the following methods
@interface Calculator : NSObject {
}
@property (nonatomic, retain) start;
@property (nonatomic, retain) add:(NSInteger) a with:(NSInteger) b;
@property (nonatomic, retain) subract:(NSInteger) a by:(NSInteger) b;;
@end;
I have a UIWebview, in which I am loading HTML with JS. Here, I have a JS script function like
function callNativeClass() {
window.calc.start;
}
"calc" is the instance or namespace of the class. I need to call the start method from JS.
Can you please tell me, is there any option to call native objective-c class like PhoneGap?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Phonegap 就是这样做的。从phonegap.com 下载框架。您可以非常轻松地创建自定义插件来调用 Objective C 文件中的方法。试试这个
http://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS
Phonegap does this. Download the framework from phonegap.com. You can create a custom plugin very easily to call the methods in Objective C file. Try this
http://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS