iOS 找不到插件,Android 没问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19447827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:24:41  来源:igfitidea点击:

iOS unable to find plugins, Android fine

iosxcodecordova

提问by Mike

I am building an app in Phonegap/Cordova. App is fairly simple at the moment, but does require the network status and geolocation plugins to work.

我正在 Phonegap/Cordova 中构建一个应用程序。应用程序目前相当简单,但确实需要网络状态和地理定位插件才能工作。

I've developed the app so far (it's made up of just a few basic HTML pages and a bit of JS at the moment) on Android and it has been working fine.

到目前为止,我已经在 Android 上开发了该应用程序(目前它仅由几个基本的 HTML 页面和一些 JS 组成),并且运行良好。

This morning I decided to make sure all was well with iOS. To absolutely no surprise at all, it isn't.

今天早上我决定确保 iOS 一切正常。毫不奇怪,事实并非如此。

So... it appears to be a problem with the plugins. XCode spits out the following:

所以......这似乎是插件的问题。XCode 吐出以下内容:

CDVPlugin class CDVLocation (pluginName: Geolocation) does not exist.
2013-10-18 11:24:29.437 Eye Cab[589:907] ERROR: Plugin 'Geolocation' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2013-10-18 11:24:29.438 Eye Cab[589:907] -[CDVCommandQueue executePending] [Line 117] FAILED pluginJSON = [
  "Geolocation1841912763",
  "Geolocation",
  "getLocation",
  [
    false,
    0
  ]
]

I guess this means it can't load the Geolocation plugin. I get a similar thing for the network connection plugin.

我想这意味着它无法加载 Geolocation 插件。对于网络连接插件,我得到了类似的东西。

Below is my truncated config.xml from the Phonegap project:

下面是我从 Phonegap 项目中截取的 config.xml:

<feature name="http://api.phonegap.com/1.0/device" />
<feature name="Geolocation">
    <param name="ios-package" value="CDVLocation" />
</feature>
<feature name="NetworkStatus">
    <param name="ios-package" value="CDVConnection" />
</feature>

I have also tried using the IDs as the feature name (eg. org.apache.cordova.geolocation), but get the same problem. The exact same error in fact.

我也尝试使用 ID 作为功能名称(例如 org.apache.cordova.geolocation),但遇到了同样的问题。实际上完全相同的错误。

Everything works perfectly in Android; in the simulator, in Chrome on my mac and on a device.

一切都在 Android 中完美运行;在模拟器中,在我的 Mac 和设备上的 Chrome 中。

I am using the following versions:

我正在使用以下版本:

  • Phonegap 3.1.0-0.15.0
  • XCode 5.0
  • OSX 10.8.5
  • iOS 6.1.3 (iPod Touch)
  • iOS Simulator for iOS 7
  • Phonegap 3.1.0-0.15.0
  • 代码 5.0
  • OSX 10.8.5
  • iOS 6.1.3 (iPod Touch)
  • 适用于 iOS 7 的 iOS 模拟器

The correct files are in the /www/plugins/ folder in the project:

正确的文件位于项目的 /www/plugins/ 文件夹中:

  • org.apache.cordova.geolocation
    • www
      • Coordinates.js
      • Position.js
      • PositionError.js
      • geolocation.js
  • org.apache.cordova.network-information
    • www
      • Connection.js
      • network.js
  • org.apache.cordova.geolocation
    • 万维网
      • 坐标.js
      • 位置.js
      • 位置错误.js
      • 地理定位.js
  • org.apache.cordova.network-信息
    • 万维网
      • 连接.js
      • 网络.js

An elated hug for anyone who can help with this. I've trawled through the other questions but with no luck.

对任何可以帮助解决此问题的人来说,这是一个欣喜若狂的拥抱。我已经浏览了其他问题,但没有运气。

采纳答案by Mike

iOS was missing the plugin files themselves (.m and .h files), which must be copied by calling cordova prepareor phonegap prepare. Not very well documented it seems.

iOS 缺少插件文件本身(.m 和 .h 文件),必须通过调用cordova prepare或进行复制phonegap prepare。似乎没有很好的记录。

回答by shi11i

Mark's solution works but is unnecessary and will cause you to lose customizations to your XCode project.

Mark 的解决方案有效但没有必要,并且会导致您丢失对 XCode 项目的自定义。

What fixed it for me was:

为我修复的是:

In XCode, goto Build Phases -> open the Compiled Sources dropdown. Click + and add the missing plugin .m file that should be in your Plugins directory (but is missing from the compiled sources).

在 XCode 中,转到 Build Phases -> 打开 Compiled Sources 下拉列表。单击 + 并添加应该在您的 Plugins 目录中的缺失插件 .m 文件(但在编译源中缺失)。

回答by Mark Pruce

For future searchers - the solution that worked for me came from another stack overflow response, here: https://stackoverflow.com/a/19501579/1245276

对于未来的搜索者 - 对我有用的解决方案来自另一个堆栈溢出响应,这里:https: //stackoverflow.com/a/19501579/1245276

In short: 1. delete ./plugins/ios.json, 2. then delete ./platforms/ios, 3. then run cordova platform add ios4. then cordova build. Deleting ios.json helps to force it to recompile the plugins, at least thats what I understand and it worked for me.

简而言之:1. 删除 ./plugins/ios.json, 2. 然后删除 ./platforms/ios, 3. 然后运行cordova platform add ios4. 然后cordova build. 删除 ios.json 有助于强制它重新编译插件,至少这是我的理解并且它对我有用。

回答by Anubhav Gupta

In my case i was unable to find Plugin_name.m file in the plugins directory as well, so i manually added the Plugin_name.m file in build phases (you can find Plugin_name.m file in plugin->src->ios folder) and then copy the feature name of plugin from ios.json file (which is present in cordova-builds folder) and add it to config.xml file(remove back-slashes). Plugin will work fine.

就我而言,我也无法在 plugins 目录中找到 Plugin_name.m 文件,因此我在构建阶段手动添加了 Plugin_name.m 文件(您可以在 plugin->src->ios 文件夹中找到 Plugin_name.m 文件)和然后从 ios.json 文件(位于cordova-builds文件夹中)复制插件的功能名称并将其添加到config.xml文件(删除反斜杠)。插件将正常工作。

Note:- You may have to add all the files in build phases which is included in plugin_name.m file.

注意:- 您可能必须在构建阶段添加包含在 plugin_name.m 文件中的所有文件。