swift - 为 Ionic 应用程序开发 Cordova 插件时出错,应用程序未使用 Ionic 2 构建 Ios 命令构建,它找不到框架类

标签 swift cordova ionic2 cordova-plugins

我正在开发一个 Ionic 2 应用程序,它使用一些 native 功能来录制具有特殊设置的视频,并允许用户在弹出窗口中更改它们,这是作为 Swift 中的框架开发的,并作为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 控制台命令构建应用程序时,我收到错误:“‘VideoRecorderPluginDelegate’不可用:找不到此协议(protocol)的 Swift 声明”和“‘VideoRecordingViewController’不可用:找不到此类的 Swift 声明”,这些类在框架内声明为公共(public)并使用 @objc 公共(public)类,我可能会缺少什么?

请帮忙!

最佳答案

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

关于swift - 为 Ionic 应用程序开发 Cordova 插件时出错,应用程序未使用 Ionic 2 构建 Ios 命令构建,它找不到框架类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43023201/

相关文章:

swift - 如何在其他 View 中使用 Swift 中的 AVPlayer 暂停和播放音乐

ios - 条件绑定(bind)的初始化程序必须具有 Optional 类型,而不是 '[AnyHashable : Any]'

ios - 权限 Cordova iPhone 插件

javascript - 设备收到 GCM Android 通知但未显示

ionic2 - Ionic 2/cordova-plugin-file File.writeFile() 拒绝正确创建二进制文件(png 图像)

android - 使用 Ionic 和 Socket.IO 的内容安全策略

ios - 如何在 Swift3 中使用可选动画实现功能

objective-c - Swift 长按结果

javascript - 无法在不同页面的 div 上加载 Highcharts

html - 从模式页面提交时启用 ionic 导航栏按钮