Skip to main content

iOS / macOS SDK quick integration

The current release is MeshStreamKit 1.0.8. One package includes iOS device components and universal iOS simulator and macOS components.

MeshStreamKit provides P2P media delivery acceleration for iOS and macOS applications. Its Objective-C APIs integrate with AVPlayer and compatible third-party players.

Official packages, sample projects, and release notes are available in the SDK repository.

Before running the code, complete Installation and setup, prepare your SDK Key and playable media URL, and configure the application network policy.

Start playback​

Retain the playback objects​

Retain the client, playback session, and player in a playback manager or view controller for the duration of playback:

@property(nonatomic, strong) P2PClient *client;
@property(nonatomic, strong) PlaybackSession *session;
@property(nonatomic, strong) AVPlayer *player;

Create a playback session​

Initialize the client with an SDK Key, create a session for the media URL, and pass its playbackUrl to the player. In this example, originURL is the original media URL:

#import <AVFoundation/AVFoundation.h>
#import <MeshStreamKit/MeshStreamKit.h>

P2PConfig *config = [[P2PConfig alloc] initWithKey:@"YOUR_IOS_SDK_KEY"];
NSError *error = nil;
self.client = [P2PSDK clientWithConfig:config error:&error];
if (!self.client) {
NSLog(@"SDK initialization failed: %@", error);
return;
}

self.session = [self.client createPlaybackSessionWithURL:originURL error:&error];
if (!self.session) {
NSLog(@"Playback session creation failed: %@", error);
return;
}

self.player = [AVPlayer playerWithURL:self.session.playbackUrl];
[self.player play];

Attach self.player to the application's playback view. Third-party players use the same session-provided playbackUrl.

If client or session creation fails, handle the returned NSError. Initialize the player only after session creation succeeds.

Release playback resources​

When changing content or ending playback, pause the player and detach the media item before closing the session:

[self.player pause];
[self.player replaceCurrentItemWithPlayerItem:nil];
[self.session close];
self.session = nil;

[P2PSDK shutdown] releases global resources. Call it only when the application no longer uses any SDK clients or sessions. Closing an individual playback screen requires closing only its session. Retain the required playback objects while Picture in Picture or background playback continues.

Common configuration​

Set client options through P2PConfig. Configuration takes effect when the client is created.

PropertyDefaultDescription
sdkKeyRequiredPlatform-specific SDK Key passed to initWithKey:
p2pEnabledYESP2P acceleration switch, subject to console policy
maxPeerConnections12Maximum peer connections
maxUploadPeers4Maximum concurrent upload peers
maxDownloadPeers5Maximum concurrent download peers
maxMemoryBytes64 MiBSDK media cache capacity limit
requestTimeoutMs8000P2P media request timeout in milliseconds
logLevelP2PLogLevelNoneLog level: None / Error / Info / Debug
fileLoggingEnabledNOSaves local diagnostic logs when enabled

maxMemoryBytes limits only the SDK media cache, excluding player and other application memory. requestTimeoutMs does not control player startup timeouts.

Preloading​

Preloading is optional and prepares content for subsequent playback. Create a separate session and call [session preload]. Reuse its playbackUrl when playback starts, or call [session close] to cancel.

Preloading consumes network traffic. A successful return means the preload request was accepted, not that downloading or first-frame rendering is complete. See Advanced Usage for session management and content switching.

Events and statistics​

Subscribe to acceleration events through P2PEventListener, or call [session statistics] to retrieve current session metrics.

FieldDescriptionUnit
httpDownloadedHTTP download trafficBytes
p2pDownloadedP2P download trafficBytes
p2pUploadedP2P upload trafficBytes
connectedPeersConnected peersCount

Diagnostic logs​

Logging is disabled by default. For diagnostics, set the log level and file logging option before creating the client:

config.logLevel = P2PLogLevelInfo;
config.fileLoggingEnabled = YES;

Log files are stored in the application's Caches directory, rotate automatically, and are not uploaded automatically. Enable logging as needed in production, and remove SDK Keys, credentials, and sensitive media URLs before sharing diagnostics.

Compatibility and common questions​

Which players and media formats are supported?​

The player must support loading the SDK-provided playback URL. Media format, decoding, DRM, background playback, and Picture in Picture support depend on the selected player, operating system, and application configuration. Configure audio sessions and background capabilities according to the player documentation.

Does a peer count of zero indicate a playback error?​

connectedPeers is the number of connected peers, not a player status. When P2P is unavailable, evaluate playback using player errors and media-source state. See Troubleshooting for diagnostic steps.

What if CocoaPods cannot resolve the dependency?​

Confirm that the Pod name is MeshStreamKit, then run pod install --repo-update. Public indexes may take time to synchronize a new release. If needed, use the versioned remote podspec installation method in the SDK repository. For CocoaPods integration, use the official published Pod rather than a :git source dependency.

Examples and support​

SDK use and distribution are governed by the applicable commercial agreement. Retain the third-party notices when distributing the application, and complete the required privacy disclosures and device compatibility validation.

Next steps​

Advanced Usage · Quickstart · Troubleshooting

Related guides: Installation and setup · Advanced usage.