Phonegap - 扩展 iOS 插件

发布于 2025-01-08 09:41:04 字数 665 浏览 1 评论 0原文

我一直在阅读有关如何为 Phonegap 创建新插件的信息,并且似乎通过遵循本教程获得了它。

http://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS

但是,我遇到了困难掌握如何扩展现有插件。 (不创建新的)
一直在阅读本教程。

http://hiediutley.com/ 2011/03/28/phonegap-tutorial-series-3-extending-the-phonegap-api/

我似乎无法找到可以添加行的位置例如,将代码添加到 .m 文件中。在我的 XCode 中,我只看到 .h 文件,但看不到 .m 文件。
或者有更好的方法来扩展 api 吗?

谢谢你,
球座

I've been reading about how to create a new plugin for Phonegap and seems to get it by following this tutorial.

http://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS

However, I'm having a hard time grasping how to extend an existing plugin. (not creating a new one)
Been reading this tutorial.

http://hiediutley.com/2011/03/28/phonegap-tutorial-series-3-extending-the-phonegap-api/

I can't seem to get where I can possibly add line of codes to the .m file for example. In my XCode, I only see the .h files but not the .m file.
Or is there a better way to extend an api?

Thank you,
Tee

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海不蓝 2025-01-15 09:41:04

编辑:这个答案不再完全正确。

最新版本的 Cordova / PhoneGap 并不是作为编译框架提供的,调整特定应用程序使用的 cordova 版本要容易得多(尤其是从 2.2.0 开始),因为它只是 XCode 中的一个子项目。

要获取 .m 文件,您必须下载 PhoneGap (Cordova) iOS 源代码并进行更改,以编译您自己版本的 PhoneGap 框架。

这并不像听起来那么难,但如果您不太熟悉 Objective-C 和命令行编译工具,可能会有点令人畏惧。

解释 iOS 源代码中的 README,例如:

$ git clone http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios.git

进行更改,然后...

  1. 启动“Terminal.app”
  2. 导航到Makefile所在的文件夹(./PhoneGapLib?)
  3. 输入make然后按Enter键

这应该构建“PhoneGapInstaller.dmg”进入 dist 文件夹。这是您用来安装新版本 PhoneGap 的工具。

另一种选择是获取您正在扩展的 API 的 .m 和 .h 文件(只需从 GitHub 源存储库获取它们)并将它们制作成具有您自己名称的新插件。举个例子,我没有扩展 Camera API 并对 Camera.m 进行更改并重新编译等...我选择制作一个最初名为 MyCamera 的插件,其中包含来自 Camera API 的代码和我自己的扩展。 PhoneGap 中的大多数 API(至少在 iOS 中)基本上本身就已经是插件了,因此它们不需要太多调整就可以变成专门用于您目的的插件。

此方法还意味着您可以稍后升级 PhoneGap,而不会破坏所有扩展。

EDIT: This answer is no longer completely correct.

The latest versions of Cordova / PhoneGap do not come as a compiled framework and it is much easier (especially since 2.2.0) to tweak the version of cordova a particular app uses as it is simply a sub-project in XCode.

To get at the .m files you would have to download the PhoneGap (Cordova) iOS source and make your changes them compile your own version of the PhoneGap framework.

That is not as hard as it sounds, but can be a bit daunting if you are not super comfortable with Objective-C and command line compilation tools.

To paraphrase the README from the iOS source, for example:

$ git clone http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios.git

Make your changes, then...

  1. Launch "Terminal.app"
  2. Navigate to the folder where the Makefile is (./PhoneGapLib ?)
  3. Type in make then press Enter

This should build "PhoneGapInstaller.dmg" into the dist folder. This is what you use to install your new version of PhoneGap.

Another option is to take the .m and .h files of the API you are extending (by simply getting them from the GitHub source repository) and making them into a new plugin with your own name. As an example, rather than extend the Camera API and make changes to Camera.m and recompile etc... I chose to make a plugin unoriginally called MyCamera that had the code from the Camera API and my own extensions. Most of the APIs in PhoneGap (at least in iOS) are basically already plugins in their own right, so they don't need much tweaking to be turned into a plugin just for your purposes.

This method also means you can upgrade PhoneGap later and not clobber all your extensions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文