Menu
How to convert Opentok iOS video SDK into a SPM package.

Kenny Domingo
- Updated
This article may be out of date! Please visit our new help center api.support.vonage.com
Objective
Vonage Video SDK (also known as Opentok) is available only via Cocoapods. This page explains how to convert this SDK into an SPM package. This is a workaround until an official SPM package is released by Vonage.
Applies To
- Video API
- Vonage iOS Client SDK
Procedure
- Download the Opentok XCFramework package from Cocoapods.
- Extract the Pods/OTXCFramework/OpenTok.xcframework to a new folder Opentok-SPM-x.y.z
- Create a Package.swift file in the Opentok-SPM-x.y.z folder describing the package.
- Create a local git repo, commit and add a tag.
- Use the full path to the Opentok-SPM-x.y.z folder as the package path in Xcode and install it.
The BASH script below performs the above tasks 1-4.
Execute the script as shown below to generate the SPM package for Opentok SDK 2.23.0
#!/bin/bash
generate_podfile(){
echo "platform :ios, '12.0'
install! 'cocoapods', integrate_targets: false
use_frameworks!
pod 'OTXCFramework', '$1'
" > Podfile
}
generate_spm_info(){
rm -f Package.swift
echo "// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: \"OpenTok\",
products: [
.library(
name: \"OpenTok\",
targets: [\"OpenTok\"]),
],
dependencies: [
],
targets: [
.binaryTarget(name: \"OpenTok\",
path: \"OpenTok.xcframework\")
]
)" > Opentok-SPM-$1/Package.swift
}
move_xcframework(){
rm -rf Opentok-SPM-$1
mkdir Opentok-SPM-$1
mv -f Pods/OTXCFramework/OpenTok.xcframework Opentok-SPM-$1
cd Opentok-SPM-$1
git init -b master
git add *
git commit -q -m "initial commit"
git tag $1
cd ..
rm -f Podfile
rm -f Podfile.lock
rm -rf Pods
}
echo "Generating Podfile for SDK version" $1
generate_podfile $1
echo "Installing pods"
pod install
echo "Extracting XCFramework"
move_xcframework $1
echo "Generating SPM package"
generate_spm_info $1
Replace
dependencies: [], |
With: (or the latest version available)
dependencies: [ |
Additional Information
Optionally, you can push this git repo to a remote location and use the remote repo while adding the SPM package in swift. You will need to make a small change in the Package.swift file, though. However, we found that GitHub has a limit of 100MB per file and XCode SPM installer doesn’t support git-lfs.
Comments
0 comments
Article is closed for comments.