为Ionic app开发Cordova插件时出错,app没有使用Ionic 2 build Ios命令构建,它没有找到框架类

时间:2017-03-25 23:35:55

标签: swift cordova ionic2 cordova-plugins

我正在开发一个Ionic 2应用,它使用一些原生功能来录制带有特殊设置的视频,并允许用户在弹出窗口中更改它们,这是作为Swift中的框架开发的,并集成到Ionic应用程序中作为Cordova插件。

这是我的config.xml:

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

这是CameraRecording.js:

var exec = require('cordova/exec');

exports.echo = function(arg0,arg1,arg2,arg3, success, error) {
  exec(success, error, "CameraRecording", "echo", [arg0,arg1,arg2,arg3]);
};

这是Swift代码:

import CameraRecording
@objc(CameraRecording) class CameraRecording : CDVPlugin, VideoRecorderPluginDelegate {

    private var callbackId:String?

    @objc(echo:) func echo(_ command: CDVInvokedUrlCommand) {
        self.callbackId = command.callbackId
        self.commandDelegate.run {
            let uuid = UUID().uuidString
            let fileName = command.arguments[0] as? String ?? "\(uuid).mp4"
            let defaultResolution = command.arguments[1] as? String ?? "640x480"
            let defaultFPS = command.arguments[2] as? String ?? "30"
            let maxRecordingTime = command.arguments[3] as? String ?? "0"


            if fileName.characters.count > 0 {

                let frameworkBundle = Bundle(identifier: "com.brainshark.CameraRecording")
                let storyboard = UIStoryboard(name: "Main", bundle: frameworkBundle)

                let viewController = storyboard.instantiateViewController(withIdentifier: "VideRecordingViewController") as! VideoRecordingViewController
                viewController.delegate = self
                viewController.fileName=fileName
                viewController.defaultResolution = defaultResolution
                viewController.defaultFPS = defaultFPS
                viewController.maxRecordingTime=maxRecordingTime

                self.viewController?.present(
                    viewController,
                    animated: true,
                    completion: nil
                )

            }
        }

    }

    func videoRecordDidFinish(_ filePath: String, recordedDuration:String, fileSize:String) {
        let pluginResult = CDVPluginResult(
            status: CDVCommandStatus_OK,
            messageAs:["filePath":filePath,"recordedDuration":recordedDuration, "fileSize":fileSize]
        )

        self.commandDelegate!.send(
            pluginResult,
            callbackId: self.callbackId
        )
    }

    func videoRecordDidFail(error: String) {
        let pluginResult = CDVPluginResult(
            status: CDVCommandStatus_ERROR,
            messageAs:error
        )

        self.commandDelegate!.send(
            pluginResult,
            callbackId: self.callbackId
        )
    }
}

如果我从XCode构建应用程序但是当使用Ionic控制台命令构建应用程序时我得到了错误:&#34;&#39; VideoRecorderPluginDelegate&#39;不可用:找不到此协议的Swift声明&#34;和&#34;&#39; VideoRecordingViewController&#39;不可用:找不到此类的Swift声明&#34;这是在框架内声明为public并使用@objc公共类的类,我可以缺少什么?

请帮忙!

1 个答案:

答案 0 :(得分:0)

我在特定设备架构上构建框架,选择“通用iOS设备”解决了问题。