Copy the framework
Unzip files, then drag and drop SwarmCloudSDK.xcframework and WebRTC.xcframework into your Xcode project on your application targets’ General settings tab, in the Frameworks, Libraries, and Embedded Content section.
Copy https://ecocdn.net/ios_sdk/SwarmCloudSDK.xcframework.zip
https://ecocdn.net/ios_sdk/WebRTC.xcframework.zip
In order to allow the loading of distributed content via the local proxy, enable loading data from HTTP in your app by opening your info.plist file as source code and adding the following values below the tag:
Copy <key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Import SwarmCloudSDK in AppDelegate.m :
swift
objective-c
Copy #import <SwarmCloudSDK/SwarmCloudSDK.h>
Initialize SWCP2pEngine
Initialize SWCP2pEngine in AppDelegate.m :
swift
Copy func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SWCP2pEngine.sharedInstance().start(token: YOUR_TOKEN, p2pConfig: nil)
return true
}
objective-c
Copy - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[SWCP2pEngine sharedInstance] startWithToken:YOUR_TOKEN andP2pConfig:nil];
return YES;
}
Where YOUR_TOKEN is your Customer ID.
Usage
When initializing an AVPlayer (or any other video player) instance, before passing it a URL, pass that URL through P2P Engine:
swift
Copy let orginalUrl = URL.init(string: "https://your_stream.m3u8")
let parsedUrl = SWCP2pEngine.sharedInstance().parse(streamURL: orginalUrl)
_player = AVPlayer.init(url: parsedUrl)
objective-c
Copy NSURL *originalUrl = [NSURL URLWithString:@"https://your_stream.m3u8"];
NSURL *parsedUrl = [[SWCP2pEngine sharedInstance] parseStreamURL:originalUrl];
_player = [[AVPlayer alloc] initWithURL:parsedUrl];
That’s it! SDK should now be integrated into your app.