Skip to content

Commit 1e83603

Browse files
committed
iOS Examples for downloading conversations media
1 parent 346921f commit 1e83603

File tree

2 files changed

+16
-42
lines changed

2 files changed

+16
-42
lines changed
Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
// Set up output stream for media content
2-
NSString *tempFilename = [NSTemporaryDirectory() stringByAppendingPathComponent:message.mediaFilename ? @"file.dat" : message.mediaFilename];
3-
NSOutputStream *outputStream = [NSOutputStream outputStreamToFileAtPath:tempFilename append:NO];
4-
5-
// Request the start of the download
6-
[message getMediaWithOutputStream:outputStream
7-
onStarted:^{
8-
// Called when download of media begins.
9-
} onProgress:^(NSUInteger bytes) {
10-
// Called as download progresses, with the current byte count.
11-
} onCompleted:^(NSString * _Nonnull mediaSid) {
12-
// Called when download is completed, with the new mediaSid if successful.
13-
// Full failure details will be provided through the completion block below.
14-
} completion:^(TCHResult * _Nonnull result) {
15-
if (!result.isSuccessful) {
16-
NSLog(@"Download failed: %@", result.error);
17-
} else {
18-
NSLog(@"Download successful");
19-
}
20-
}];
1+
if (message.hasMedia) {
2+
[message getMediaContentTemporaryUrlWithCompletion:^(TCHResult * _Nonnull result,
3+
NSString * _Nullable mediaContentURL) {
4+
if (result.isSuccessful) {
5+
// Use the url to download an image or other media
6+
NSLog(@"%@", mediaContentURL);
7+
}
8+
}];
9+
}
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
// Set up output stream for media content
2-
let tempFilename = (NSTemporaryDirectory() as NSString).appendingPathComponent(message.mediaFilename ?? "file.dat")
3-
let outputStream = OutputStream(toFileAtPath: tempFilename, append: false)
4-
5-
// Request the start of the download
6-
if let outputStream = outputStream {
7-
message.getMediaWith(outputStream,
8-
onStarted: {
9-
// Called when download of media begins.
10-
},
11-
onProgress: { (bytes) in
12-
// Called as download progresses, with the current byte count.
13-
},
14-
onCompleted: { (mediaSid) in
15-
// Called when download is completed, with the new mediaSid if successful.
16-
// Full failure details will be provided through the completion block below.
17-
}) { (result) in
18-
if !result.isSuccessful() {
19-
print("Download failed: \(String(describing: result.error))")
20-
} else {
21-
print("Download successful")
1+
if message.hasMedia() {
2+
message.getMediaContentTemporaryUrl { (result, mediaContentUrl) in
3+
guard let mediaContentUrl = mediaContentUrl else {
4+
return
225
}
6+
// Use the url to download an image or other media
7+
print(mediaContentUrl)
238
}
24-
}
9+
}

0 commit comments

Comments
 (0)