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
- Objective-C
swift
import NexconnChatSDK
message downloadMediaWithProgressHandler:^(int progress) {
// 0-100
}
successHandler:^(NSString *mediaPath) {
// Downloaded to mediaPath
}
errorHandler:^(NCError *error) {
// Failed
}
cancelHandler:^{
// Cancelled
}
Objective C
[message downloadMediaWithProgressHandler:^(int progress) {
// 0-100
}
successHandler:^(NSString *mediaPath) {
// Downloaded to mediaPath
}
errorHandler:^(NCError *error) {
// Failed
}
cancelHandler:^{
// Cancelled
}];
Pause download
- Swift
- Objective-C
swift
import NexconnChatSDK
message pauseDownloadingMediaWithCompletion:^(NCError *error) {
// Paused
}
Objective C
[message pauseDownloadingMediaWithCompletion:^(NCError *error) {
// Paused
}];
Cancel download
- Swift
- Objective-C
swift
import NexconnChatSDK
message cancelDownloadingMediaWithCompletion:^(NCError *error) {
// Cancelled
}
Objective C
[message cancelDownloadingMediaWithCompletion:^(NCError *error) {
// Cancelled
}];
Download by URL
- Swift
- Objective-C
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)
}
Objective C
NCMediaDownloadInfo *info =
[NCBaseChannel 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.