如何使用phonegap插件
我是phonegap开发的新手。我为 iphone 创建了一个插件类,其中包含一些加密方法。我想使用 .h 和 .m 文件来加密我的数据并从 html 页面中的类文件中获取数据。但我不知道如何在我的 javascript 文件中调用该类函数作为我的页面的结果。请任何人知道如何在 iPhone 应用程序的 javascript 中调用任何类文件及其方法,然后帮助我。我正在等待回复。
I am new in phonegap development . I have created one plugin class for iphone which contains some method for encryption. I want to use that .h and .m file to encrypt my data and get the data from my class file in my html page. But i don't have any idea how to call that class function in my javascript file as a result of my page. Please any one have idea how to call any class file and its method in javascript for iphone application then help me .I am waiting for reply.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅保罗回答的链接。为了快速运行,有几种方法可以做到这一点,但我的通常会得到这样的结果。
Javascript:
Objective C:
回到 Javascript:
还要记住您需要在 Phonegap.plist 中注册您的插件
希望这有帮助,祝你好运。
更新:如果您希望 html 将信息发送到您的插件,我会使用 html 表单或按钮或触发一个操作来调用您的 javascript 函数(上面的第一个)并传递您的变量从你的田地里采集来的。请参阅此链接了解表单基础知识。
更新2
1)在xcode中创建新的phonegap项目并构建以获取www文件夹
2)将现有的加密目标 C 文件添加到项目
3)创建新的目标C类,将其命名为EncryptPlugin(下一步参见步骤5)
4)编辑PhoneGap.plist文件
a) 在插件下添加一个新条目
b) 将其命名为 EncryptPlugin String EncryptPlugin
5) EncryptPlugin 的头文件应如下所示
6) 实现文件应如下所示
7) 在您的 html javascript 中使用类似以下内容调用函数
p1.html
这应该可以帮助您入门。如果您想将内容发送回您的 html javascript,请使用我上面指定的函数:
希望这会有所帮助,您应该能够通过这些说明弄清楚它。它们可能并不完美,但我没有时间将它们放在一起并使用您的代码进行编译。祝你好运。
See the link that Paul answered. For a quick run down, there are a couple ways to do this, but mine usually end up something like this.
Javascript:
Objective C:
Back to Javascript:
Also remember you need to register your plugin in your Phonegap.plist
Hope this helps, good luck.
Update: If you want your html to send information to your plugin, i'd use an html form or button or trigger an action that will call your javascript function (The first one above) and pass your variables gathered from your fields. See this link for form basics.
Update 2
1)Create new phonegap project in xcode and build to get www folder
2)Add your existing Encryption objective C files to project
3)Create new objective C class, call it EncryptPlugin (See step 5 for next)
4)Edit PhoneGap.plist file
a)add a new entry under Plugins
b)name it EncryptPlugin String EncryptPlugin
5)Header file for EncryptPlugin should look like this
6)Implementation file should look like this
7)In your html javascript call the function using something like this
p1.html
This should get you started. If you want to send stuff back to your html javascript then use the function I specified above:
Hopefully this helps, you should be able to figure it out with these instructions. They probably aren't perfect, but I didn't have time to put it all together and compile it using your code. Good luck.
请参阅如何创建 PhoneGap 插件适用于 iOS
See How to Create a PhoneGap Plugin for iOS