ionic cordova build ios fail installing custom plu

2019-07-09 02:34发布

问题:

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..

I'm working with cordova cli 7.0.1 and cordova-ios": ^4.4.0. in the plugin config.xml file I'm using

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 **

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>

my swift file:

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 file:

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

回答1:

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.