ionic cordova build ios 使用 xcode swift 3 框架安装自定义插件失败

Posted

技术标签:

【中文标题】ionic cordova build ios 使用 xcode swift 3 框架安装自定义插件失败【英文标题】:ionic cordova build ios fail installing custom plugin with xcode swift 3 framework 【发布时间】:2017-07-24 13:10:19 【问题描述】:

我正在尝试从我创建的 ios 框架中读取一个函数,该框架已添加到自定义 cordova 插件中。 正如一些帖子中所建议的那样,我已将框架编译为“通用 iOS 设备”,但我在使用框架功能时仍然遇到问题..

我正在使用cordova cli 7.0.1 和cordova-ios”:^4.4.0。 在我正在使用的插件 config.xml 文件中

添加我的框架但调用我的函数(在尝试读取框架函数的插件中)返回: 错误:“打印机”不可用:找不到此类的 Swift 声明: 让 printtt = testtest.printer(); ^~~~~~~ testtest.printer:2:12:注意:“打印机”已在此处明确标记为不可用 开放类打印机:NSObject ^ /platforms/ios/MyApp/Plugins/com-moduscreate-plugins-echo/ModusEchoSwift.swift:11:5: 错误:“打印机”类型的值没有成员“printlocal” printtt.printlocal(); ^~~~~~~ ~~~~~~~~~~

** BUILD FAILED **

有人遇到过这样的问题吗? PS。我的框架包含一个带有公共方法的公共类打印机 我在 xcode 8.xx 下测试过的 printlocal

**my plugin.xml file:** 
<?xml version='1.0' encoding='utf-8'?>
<plugin id="com-moduscreate-plugins-echo" version="0.0.1" 
xmlns="http://apache.org/cordova/ns/plugins/1.0" 
xmlns:android="http://schemas.android.com/apk/res/android">
    <name>ModusEcho</name>
    <js-module name="ModusEcho" src="www/ModusEcho.js">
        <clobbers target="modusEcho" />
    </js-module>
    <platform name="ios">
       <framework src="src/ios/testtest.framework" custom="true" embed="true" />
        <config-file target="config.xml" parent="/*">
            <feature name="ModusEcho">
                <param name="ios-package" value="ModusEchoSwift" />
            </feature>
        </config-file>
        <source-file src="src/ios/ModusEchoSwift.swift" />
    </platform>
</plugin>

我的 swift 文件:

import testtest
@objc(ModusEchoSwift) class ModusEchoSwift : CDVPlugin
  @objc(echocrypt:)
  func echocrypt(command: CDVInvokedUrlCommand) 
    var pluginResult = CDVPluginResult(
      status: CDVCommandStatus_ERROR
    )

    let printtt = testtest.printer();
    printtt.printlocal();
  


**my dynamic framework class:** 
import Foundation
public class printer:NSObject 
    public func printlocal() 
        print("from printer!!!");

    

www/modusecoh.js 文件:

var exec = require('cordova/exec');
exports.echocrypt = function(arg0, success, error) 
    exec(success, error, "ModusEcho", "echocrypt"`enter code here`, [arg0]);
;

【问题讨论】:

【参考方案1】:

发现问题: 由于我使用了“cordova-plugin-add-swift-support”插件,它已将项目的 ios min 部署目标设置为 7.0,因此框架(动态库)仅从 8.0 开始引入 当将插件 IOS_MIN_DEPLOYMENT_TARGET 全局变量值更改为 8.0 时,(重新编译后),它已经开始工作了! 因此,上面的代码是使用 swift3 编写的来自 cordova 自定义插件的 xcode 框架的方式。

【讨论】:

我更喜欢运行 ionic build ios --device(设备部分可以跳过),因为我将在项目本身中查看是否所有构建到设备的过程都成功完成。

以上是关于ionic cordova build ios 使用 xcode swift 3 框架安装自定义插件失败的主要内容,如果未能解决你的问题,请参考以下文章

运行 ionic cordova build ios 时找不到包含的文件

IONIC 4:“ionic cordova build ios”不显示使用 Xcode 10.1 构建失败或成功

ionic cordova build ios 使用 xcode swift 3 框架安装自定义插件失败

ionic cordova build 成功,ionic cordova build --prod 报错

Ionic Cordova 不构建 android

ionic运行ionic build android出错