ios - 如何在Ionic/Cordova构建中正确引用iOS第三方框架,以免引发dyld:库未加载:@rpath错误

标签 ios objective-c cordova ionic-framework cordova-plugins

我有一个使用插件的Ionic5(cli 6.3.0)/ Cordova 9.0.3(cordova-lib@9.0.2)项目。

我正在尝试为第三方框架创建自定义插件。

我知道插件的框架是正确的,因为我是用Plugman创建的,在添加框架之前,我可以构建/运行并获得反馈,说“coolMethod”已从Objective-C文件运行。

即使添加了框架,我也可以使用ionic cordova plugin add ./packages/cordova-plugin-my-custom-stuff使插件正确安装

我可以让Ionic / Cordova使用ionic cordova build ios成功构建iOS项目

但是,当我尝试从Ionic命令行ionic cordova run ios或从自动生成的xCode项目运行iOS模拟器时,我得到了

 dyld: Library not loaded: @rpath/MyThirdPartySDK.framework/MyThirdPartySDK
 Referenced from: /Users/myUser/Library/Developer/CoreSimulator/Devices/C9E28EFF-B017-4F5E- 
 BA89-5200AE5D64EA/data/Containers/Bundle/Application/775C8394-B014-4B01-89CA- 
 1D462FD54F4A/MyName Mobile-UAT.app/MyName Mobile-UAT
 Reason: image not found

项目的结构(为简洁起见,简明扼要)如下:
 MyProject
 -node_modules
 -packages
  -cordova-plugin-my-custom-stuff
   -src
    -ios
     MyCustomStuff.m
     -MyThirdPartySDK.framework
      -Headers
       MobileAPI.h
       MyThirdPartySDK.h
      -Modules
       module.modulemap
      MyThirdPartySDK
   -www
    cordova-plugin-my-custom-stuff.js
   package.json
   plugin.xml

ios部分的plugin.xml如下所示:
<platform name="ios">
    <config-file parent="/*" target="config.xml">
        <feature name="MyCustomStuff">
            <param name="ios-package" value="MyCustomStuff"/>
        </feature>
    </config-file>
    <source-file src="src/ios/MyCustomStuff.m"/>
    <source-file src="src/ios/MyCustomStuffSDK.framework" framework="true"/>
    <header-file src="src/ios/MyCustomStuffSDK.framework/Headers/MobileAPI.h" target-dir="MyCustomStuff" />
</platform>

我正在寻找一个位于plugin.xml配置或其他一些ionic / cordovaproject配置中的解决方案。我想避免编辑xCode项目,因为这都是由ionic / cordova命令行“自动”生成的。

最佳答案

终于明白了。

  <platform name="ios">
    <config-file parent="/*" target="config.xml">
        <feature name="MyCustomPlugin">
            <param name="ios-package" value="MyCustomPlugin"/>
        </feature>
    </config-file>
    <source-file src="src/ios/MyCustomPlugin.m"/>
    <source-file src="src/ios/MyCustomPlugin.framework" target-dir="lib" framework="true" />
    <framework src="src/ios/MyCustomPlugin.framework" embed="true" custom="true" />
    <header-file src="src/ios/MyCustomPlugin.framework/Headers/MobileAPI.h" target-dir="MyCustomPlugin" />
 </platform>

关于ios - 如何在Ionic/Cordova构建中正确引用iOS第三方框架,以免引发dyld:库未加载:@rpath错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61395950/

相关文章:

javascript - 使用-webkit-overflow-scrolling :touch - Safari iOS javascript event (scrollTop/scrollLeft) 时的当前滚动位置

objective-c - 获取例程中出现死锁

javascript - 如何将从数据库中取出的数据设置为div内容?

cordova - Angular 2/ionic 2 从本地设备文件系统读取 json 文件

c++ - 如何正确处理音频中断?

ios - SKShapeNode 位置和 touch.location 的区别

objective-c - 如何将我的 nib 文件的所有者设置为另一个 nib 文件中的对象?

ios - 在 UIWebView 中加载受密码保护的 PDF

javascript - 如何在 React Native 中呈现原生 UIViewController? (不能只使用 UIView)

android - 跨 webView 和 CordovaWebView android 共享 localStorage