File tree 2 files changed +16
-42
lines changed
ip-messaging/media/retrieve-message-media
2 files changed +16
-42
lines changed Original file line number Diff line number Diff line change 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
+ }
Original file line number Diff line number Diff line change 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
22
5
}
6
+ // Use the url to download an image or other media
7
+ print ( mediaContentUrl)
23
8
}
24
- }
9
+ }
You can’t perform that action at this time.
0 commit comments