FlyreelFNOL 是一个 Swift 框架,用于捕获视频,处理整个流程,从注册、录制和预览视频,再到提供最终捕获视频文件的本地文件 URL 路径。此框架支持通过 CocoaPods 和 Swift 包管理器进行集成,可用于 SwiftUI 和 UIKit 项目。
- SwiftUI/UIKit 支持功能
- 注册流程
- 视频录制
- 视频预览
- 存储视频文件的本地路径
要使用 CocoaPods 将 FlyreelFNOL 集成到您的 Xcode 项目中,请在 Podfile 中指定它
pod 'FlyreelFNOL'
然后,运行以下命令
pod install
- 按照Apple 指南将包依赖项添加到您的应用程序中。
- 搜索
https://github.com/Flyreel/flyreel-fnol-ios
包。
在 SwiftUI 代码库中使用 FNOLCaptureView
import SwiftUI
import FlyreelFNOL
struct ContentView: View {
@State private var recordedVideoURL: URL?
@State private var isPresentingCaptureView = false
var body: some View {
Button {
isPresentingCaptureView = true
} label: {
Text("Start Capture")
}
.compatibleFullScreen(isPresented: $isPresentingCaptureView) {
FNOLCaptureView(clientID: "YOUR CLIENT ID") { url in
if let url {
// Handle the recorded video URL
print("Recorded video URL: \(url)")
} else {
print("Recording was not completed")
}
isPresentingCaptureView = false
}
}
}
}
在 UIKit 代码库中使用 FNOLCaptureView
import UIKit
import FlyreelFNOL
class ViewController: UIViewController {
@IBAction func showFNOLCaptureFlow(_ sender: UIButton) {
self.presentFNOLCaptureView(clientID: "YOUR CLIENT ID") { recordedVideoURL in
if let url = recordedVideoURL {
// Handle the recorded video URL
print("Recorded video URL: \(url)")
} else {
print("Recording was not completed")
}
}
}
}
FNOLCaptureView
是一个用于捕获视频的 SwiftUI 视图。它提供了一个完成处理程序,在用户点击上传按钮时返回已录制视频的本地文件路径。
public init(
clientID: String,
onCaptureCompletion: ((URL?) -> Void)? = nil
)
clientID
:用于验证和启用此模块的客户端 ID。onCaptureCompletion
:当用户上传已录制的视频时执行的自定义闭包。闭包将已录制视频的本地 URL 作为参数。
要在大纲中使用相机和麦克风,您需要将以下密钥添加到应用程序的 Info.plist
文件中
NSCameraUsageDescription
:一条消息,说明应用程序为什么需要访问相机。NSMicrophoneUsageDescription
:一条消息,说明应用程序为什么需要访问麦克风。
以下是这些密钥和值的示例
<key>NSCameraUsageDescription</key>
<string>We need access to the camera to record videos for the FNOL capture process.</string>
<key>NSMicrophoneUsageDescription</key>
<string>We need access to the microphone to record audio along with the video for the FNOL capture process.</string>