我正在开发一个 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/