Skip to main content

Download media files

The Chat SDK supports downloading media files from media messages.

Media message types

Built-in media message types include NCFileMessage, NCImageMessage, NCGIFMessage, NCHDVoiceMessage, and NCShortVideoMessage.

Download from a media message

After downloading, the localPath property of the media content is updated automatically.

swift
import NexconnChatSDK
message downloadMediaWithProgressHandler:^(int progress) {
// 0-100
}
successHandler:^(NSString *mediaPath) {
// Downloaded to mediaPath
}
errorHandler:^(NCError *error) {
// Failed
}
cancelHandler:^{
// Cancelled
}

Pause download

swift
import NexconnChatSDK
message pauseDownloadingMediaWithCompletion:^(NCError *error) {
// Paused
}

Cancel download

swift
import NexconnChatSDK
message cancelDownloadingMediaWithCompletion:^(NCError *error) {
// Cancelled
}

Download by URL

swift
import NexconnChatSDK
NCMediaDownloadInfo *info =
BaseChannel getMediaDownloadInfoWithMediaUrl:@"https://example.com/path/to/media"
if (info != nil) {
// NSLog("Progress: %d", info.progress)
// NSLog("Local path: %", info.localPath)
}

Use +[NCBaseChannel getMediaDownloadInfoWithMediaUrl:] to inspect an existing media download task by remote URL. To start, pause, or cancel a download, use the instance methods on NCMessage.