New iOS API client
February 2, 2022 - Thibault Beyou in iOS, API client, Swift
api.video removes the complexity from streaming video. Our simple to use APIs allow you to focus on creating your content -- leave the video streaming details to us.
Few months ago, we announced our Android API client, we are now happy to announce the release of our iOS API client. We are replacing the iOS SDK to simplify api.video usages and deployment of the new version. It also provides support for api.video progressive upload. We will focus on the progressive upload part in another blog articles.
The iOS API client comes with:
This article is a walkthrough to upload a file with iOS API client.
Installation
Cocoapods
- Add the following entry to your
Podfile
:
pod ‘ApiVideoClient’, '$lastest_version'
Then run
pod install
Import ApiVideoClient in every file you’d like to use iOS API client.
Carthage
- Add the following entry to your
Cartfile
:
github "apivideo/api.video-ios-client" ~> $lastest_version
Then run
carthage update
Import ApiVideoClient in every file you’d like to use iOS API client.
iOS API configuration
To use the iOS API client, you first have to import the ApiVideoClient
.
import ApiVideoClient
ApiVideoClient
class provides static fields and methods to configure the iOS API client. You can set your API key, your environment (sandbox or production), chunk size,...
Set your API key with:
ApiVideoClient.apiKey = "YOUR_API_KEY"
If you want to target the sandbox environment:
ApiVideoClient.basePath = Environment.sandbox.rawValue
Create a video file
If you haven't create a video on api.video, you have to create a video entry on api.video platform with:
VideosAPI.create(videoCreationPayload: VideoCreationPayload(title: "my video title", description: "my video description")) { video, error in
if let video = video {
// Get the videoId with video.videoId
}
if let error = error {
// Something bad happens
}
}
Description of the fields of VideoCreationPayload
is provided here.
Upload a video file
To upload a file, you will have to get the URL
of your file. You can get it from the image picker component. Have a look at our a sample code.
VideosAPI.upload(videoId: video.videoId, file: url) { video, error in
if let video = video {
// Video has been successfully uploaded
}
if let error = error {
// Something bad happens
}
}
If you want to draw a progress bar that displays the upload progress, there is a onProgressReady: ((Progress) -> Void)
parameter to the upload
method.
iOS API client capabilities
The iOS API client provides methods to perform every possible actions on the api.video API such as list videos (with filters), delete video, add/remove captions,... If you are not familiar with api.video API, you should have a look on api.video documentation documentation. You will find the same concepts in the iOS API client documentation.
iOS video uploader
If you want to develop an application that only uploads video files. You should have a look at the iOS video uploader.
Don't hesitate to share your feedback on our community. Happy building!
Thibault Beyou
Senior Mobile Developer
Follow our latest news by subscribing to our newsletter
Create your free account
Start building with video now