离子cordova构建ios无法使用xcode swift 3框架安装自定义插件 [英] ionic cordova build ios fail installing custom plugin with xcode swift 3 framework
问题描述
我正在尝试从我创建的iOS框架中读取一个函数,我已将其添加到自定义cordova插件中。
我已经将框架编译为通用iOS设备,正如一些帖子中所建议的那样,但我在使用框架功能时仍然存在问题..
I'm trying to read a function from an iOS framework i have created which I have added into a custom cordova plugin. I have compiled the framework as "Generic iOS Device", as was suggested in some post but i still have a problem in using the framework function..
我正在使用cordova cli 7.0.1和cordova-ios:^ 4.4.0。
在插件config.xml文件中我正在使用
I'm working with cordova cli 7.0.1 and cordova-ios": ^4.4.0. in the plugin config.xml file I'm using
添加我的框架但调用我的函数(在试图读取框架函数的插件中)返回:
错误:'printer'不可用:找不到这个类的Swift声明:
let printtt = testtest.printer();
^ ~~~~~~
testtest.printer:2:12:注意:'printer'有已明确标记为不可用
公开类打印机:NSObject {
^
/platforms/ios/MyApp/Plugins/com-moduscreate-plugins-echo/ModusEchoSwift.swift:11:5:
错误:'printer'类型的值没有成员'printlocal'
printtt.printlocal();
^ ~~~~~~~~~~~~~~~~ p>
which add my framework but calling my function (in the plugin which try to read a framework function) return: error: 'printer' is unavailable: cannot find Swift declaration for this class: let printtt = testtest.printer(); ^~~~~~~ testtest.printer:2:12: note: 'printer' has been explicitly marked unavailable here open class printer : NSObject { ^ /platforms/ios/MyApp/Plugins/com-moduscreate-plugins-echo/ModusEchoSwift.swift:11:5: error: value of type 'printer' has no member 'printlocal' printtt.printlocal(); ^~~~~~~ ~~~~~~~~~~
** BUILD FAILED **
有人遇到过这样的问题吗?
PS。我的框架包含一个公共类打印机,使用公共方法
printlocal,我已经在xcode 8.xx下测试了
does any one have encountered such a problem? PS. my framework contains a public class printer with public method printlocal which i have tested under xcode 8.xx
**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]);
};
推荐答案
发现问题:
因为我有使用cordova-plugin-add-swift-support插件,它已将项目的ios min部署目标设置为7.0,因此框架(动态库)仅在更改插件IOS_MIN_DEPLOYMENT_TARGET全局时从8.0
引入var值为8.0,(重新编译后),它已经开始工作了!
所以,上面的代码是使用来自cordova自定义插件的swift3编写的xcode框架的方式。
Found the problem: Since i have used "cordova-plugin-add-swift-support" plugin, it has set the ios min deployment target of the project to 7.0 hence the frameworks (dynamic library), were introduced only from 8.0 when changing the plugin IOS_MIN_DEPLOYMENT_TARGET global var value to 8.0, (after recompile), it has started working! so, the above code is the way of working with a xcode framework written in swift3 from cordova custom plugin.
这篇关于离子cordova构建ios无法使用xcode swift 3框架安装自定义插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!