Video Recorder
- Token Verification: Receives a token and URL, verifies it, and proceeds to video recording if valid.
- Video Recording: Requests camera and microphone access to record a 15-second clip with visual indicators.
- Returning Results: Invokes an
onFinishcallback with the result status and the local video file path.
Compatibilidad y Requisitos
Embedding and Signing the Framework
In Xcode, navigate to the “General” tab of the application target, locate the “Frameworks, Libraries and Embedded Content” section, and for the VideoRecorderUI.xcframework framework, select the “Embed & Sign” option from the “Embed” column.
Prerequisites
Camera and microphone permissions: Make sure to add the following permissions to the Info section of the project target or to the Info.plist file:
Info.plist
<key>NSCameraUsageDescription</key>
<string>Please grant permission to use the camera. By Dicio</string>
<key>NSMicrophoneUsageDescription</key>
<string>Please grant microphone permissions for the video recorder by Dicio.</string>
Usage in SwiftUI
1. Import the framework In the file where you intend to trigger video recording, import the framework:Import
import VideoRecorderUI
• token: the value obtained from your Dicio service/environment.
• urlVerify: the URL where the token will be validated.
• onFinish: a callback that receives (isSuccessful, route) upon completion.
Basic example in SwiftUI:
Usage Example
struct VideoRecorderExample: View {
@State private var showRecorder = false
@State private var resultPath: String = ""
var body: some View {
VStack {
Button("Start recording") {
showRecorder = true
}
// Presents the framework in full screen
.fullScreenCover(isPresented: $showRecorder) {
VideoRecorderVC(
token: "YOUR_PROVIDED_TOKEN",
urlVerify: "https://example.service.com",
onFinish: { isSuccessful, route in
if isSuccessful {
print("Video saved at: \\(route)")
resultPath = route
} else {
print("Error or cancellation")
}
}
)
}
Text("Last video path: \\(resultPath)")
.font(.footnote)
}
}
}
• @State private var showRecorder = false controls whether the framework view is presented as a fullScreenCover.
• When showRecorder is true, VideoRecorderVC is launched.
• The onFinish callback returns the result:
isSuccessful = true=> Recording was successful, androutewill contain the local path.isSuccessful = false=> An error occurred or the user cancelled.
- Handling the Recording Result
The
onFinishblock executes when the recording ends or if the flow is closed. For example:
Result handling
onFinish: { isSuccessful, route in
if isSuccessful {
// The video is saved in 'route'
print("Video saved at: \\(route)")
// Here you can upload it to your server or use it as needed.
} else {
// There was a problem or it was cancelled
print("Error or cancellation")
}
}
Note: The video file remains in your application's temporary or documents directory (depending on the exact SDK implementation).
Ensure you manage its lifecycle according to your needs (for example, by copying it to another secure directory or uploading it immediately if you do not wish to store it locally).
Complete Example
Complete Example
import SwiftUI
import VideoRecorderUI
struct VideoRecorder: View {
@State private var showRecorder = false
@State private var resultPath: String = ""
var body: some View {
VStack {
Button("Start recording") {
showRecorder = true
}
.fullScreenCover(isPresented: $showRecorder) {
// Call to the framework
VideoRecorderVC(
token: AppConfig.shared.bearerToken,
urlVerify: AppConfig.shared.laUrlVerifica,
onFinish: { isSuccessful, route in
// Handle the result
if isSuccessful {
print("Video saved at: \\(route)")
resultPath = route
} else {
print("Error or cancellation")
}
}
)
}
Text("Last video path: \\(resultPath)")
.font(.footnote)
}
}
}
- The "Start Recording" button opens the full sheet.
- Within that sheet,
VideoRecorderVCinternally performs token verification and, if successful, proceeds with the video recording. - Upon completion (whether successful or resulting in an error), it closes the sheet and invokes your callback.
Additional Considerations
• Error Handling: The SDK internally handles cases involving denied permissions or unauthorized tokens. If the user denies access to the camera or microphone, an alert will appear instructing them to grant the necessary permissions.
• Styling and UI: You can customize the presentation (e.g., using .sheet instead of .fullScreenCover), provided the container is a SwiftUI view.
• Integration into Existing Projects: Ensure your project supports iOS 13+ (or the minimum version you have specified). This SDK is not compatible with earlier versions.
• Versioning: Check the specific version of VideoRecorderUI.xcframework you receive, in case there are updates or API changes.