How to convert Opentok iOS video SDK into a SPM package.
Vonage Video iOS SDK (also known as Opentok iOS SDK) is available only via Cocoapods. This article explains how to convert this SDK into a SPM package. This is a workaround until an official SPM package is released by Vonage. This script works only for Opentok iOS SDK version 2.24.0 onwards.
Objective
Convert Opentok SDK on IOS to into an SPM package
Applies To
- iOS Client SDK
Procedure
- Download the Opentok XCFramework package from Cocoapods.
- Extract the Pods/OTXCFramework/OpenTok.xcframework and Pods/VonageWebRTC/VonageWebRTC.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 show below to generate SPM package for Opentok SDK 2.24.1
$ ./generateSPM.sh 2.24.2
You can also find the gist here - https://gist.github.com/rktalusani/a129c76b572ccad2b0c2c1177dc13cf4
generateSPM.sh:
#!/bin/bash generate_podfile(){ echo "platform :ios, '12.0' install! 'cocoapods', integrate_targets: false use_frameworks! pod 'OTXCFramework', '$1' " > Podfile } generate_spm_info(){ rm -rf Opentok-SPM-$1 mkdir Opentok-SPM-$1 echo '// swift-tools-version:5.6 import PackageDescription let package = Package( name: "OpenTokLib", products: [ .library( name: "OpenTokLib", targets: ["OpenTokLib","OpenTok","VonageWebRTC"]), ], dependencies: [], targets: [ .target(name: "OpenTokLib", path: "./", linkerSettings: [ .unsafeFlags(["-ObjC"]), .linkedLibrary("c++"), .linkedFramework("VideoToolbox"), .linkedFramework("Foundation"), .linkedFramework("Network") ] ), .binaryTarget(name: "OpenTok",path: "OpenTok.xcframework"), .binaryTarget(name: "VonageWebRTC",path: "VonageWebRTC.xcframework") ] ) ' > Opentok-SPM-$1/Package.swift } move_xcframework(){ mv -f Pods/OTXCFramework/OpenTok.xcframework Opentok-SPM-$1 mv -f Pods/VonageWebRTC/VonageWebRTC.xcframework Opentok-SPM-$1 cd Opentok-SPM-$1 mkdir Sources mkdir Sources/OpenTokLib touch Sources/OpenTokLib/Empty.swift git init -b master git add * git add Package.swift 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 --repo-update echo "Generating SPM package" generate_spm_info $1 echo "Extracting XCFramework" move_xcframework $1
Comments
0 comments
Please sign in to leave a comment.