File sharing
File sharing is a feature that allows users to send files such as images, audio files, and videos while chatting in a channel. File sharing appears in the messageInput component of the SBUGroupChannelViewController
or SBUOpenChannelViewController
class.
Group channel
There are currently four different types of file messages that users can send: image file, video file, audio file, and document file. These files can be shared with other members in the channel by either directly taking a photo with the camera on a mobile device or uploading an image, video, audio, or document file from the sender’s mobile device.
Note : In order to use the file sharing feature, you must first create a channel and enable the chat service. To learn how to allow users to chat in a channel, refer to Chat in a group channel.
Customize the UI for file sharing
You can customize the UI for file sharing using SBUMessageCellTheme
in the SBUTheme
, SBUStringSet
, and SBUIconSet
.
SBUMessageCellTheme
The following table shows customizable theme properties of file sharing.
Category | Property | Description |
---|---|---|
File message | fileIconBackgroundColor | The background color of the file icon. |
File message | fileIconColor | The color of the file icon. |
File message | fileMessageNameFont | The text font of the file message name element. |
File message | fileMessageLeftTextColor | The text color of the left side of a file message. |
File message | fileMessageRightTextColor | The text color of the right side of a file message. |
File message | fileMessagePlaceholderColor | The text color of a file message's placeholder. |
SBUStringSet
The following table lists customizable properties of SBUStringSet
that can be modified to customize file sharing. The SBUStringSet
is a set of strings used to compose the screen. You need to modify the stringSet
values in advance if you want to make changes to the screen.
Property name | Description |
---|---|
Channel_Success_Download_file | A text for file save completion. |
Channel_Failure_Download_file | A text for file save failure. |
Channel_Failure_Open_file | A text for file open failure. |
SBUIconSet
The following table shows customizable file sharing icons.
Icon name | Image | Description |
---|---|---|
iconAdd | Add a file. | |
iconDocument | Select a file to send. | |
iconFileAudio | An audio file message. | |
iconFileDocument | A document file message. | |
iconGif | A | |
iconPlay | Play a video file message. |
Image compression
UIKit for iOS allows users to compress images when sending them to other users in the channel on the client app. By reducing the image size, they can send and receive image files faster and minimize data storage and data usage.
The following table lists properties in the SBUGlobals
class that are related to image compression. These properties can be customized before you initialize UIKit or create a new channel.
Property | Type | Description |
---|---|---|
isImageCompressionEnabled | Bool | Determines whether to compress the image when sending an image file message. (Default: |
imageCompressionRate | CGFloat | The value of the compression rate to apply to the image. Acceptable values are 0.0 to 1.0, inclusive. (Default: |
imageResizingSize | CGSize | The value of the size dimensions to apply to the image. (Default: |
Note: To compress an image without changing the size dimensions, use the
imageCompressionRate
property. To resize the image, use theimageResizingSize
property.
Playing audio and video files
UIKit for iOS uses AVPlayerViewController
to play audio and video files. The files will play without audio when the user's device is on silent mode. However, in version 3.4.0 or later, the client app uses UIDocumentInteractionController
to play audio and video files with sound even when the user's device is on silent mode. By setting SBUGlobals.isAVPlayerAlwaysEnabled
to true
, you can still use AVPlayerViewController
in version 3.4.0 or later. The default value of the property is set to false
.
Multiple files message
Users can share multiple images and videos in a single message through a multiple files message. UIKit for iOS supports this functionality with the same UI resources and image compression used for single file messages.
Requirements
Make sure that your client app uses the latest version of the Chat SDK and UIKit to properly use multiple files messages.
- iOS v14 or higher
- Sendbird Chat SDK v4.12.1
- Sendbird UIKit v3.10.0
Depending on the version of the SDKs, multiple files messages can't be drawn in the view. For example, if a client app uses the latest Chat SDK but the UIKit lower than v3.10.0, the UIKit can't display multiple files messages at all as they don't support the functionality.
If the client app uses the Chat SDK and UIKit that don't support multiple files messages, only one file is drawn in the view as a single file message. The file that appears may vary depending on the device's OS version.
Settings
By default, multiple files messages are turned off for UIKit. In order to display them, enable the feature in AppDelegate.swift
or before entering the channel using the code below.
It is important to note that if SBUGlobals.isPHPickerEnabled
is set to false
after setting isMultipleFilesMessageEnabled
to true
, multiple files selection will not be enabled.
Also, multiple files selection is available only when the permission setting of NSPhotoLibraryUsageDescription
is set to All Photos
.
Note: Multiple files messages are supported in iOS v14 or higher.
By default, the UIKit allows up to ten files per message, 25MB per file. To adjust the number of file attachments, contact our Sales team and set multiple_file_send_max_size
to a higher or lower number. Between the UIKit's default settings and the multiple_file_send_max_size
value, the lower number is set as the maximum number of files allowed for multiple files messages. When the number or size of files selected by the current user exceeds the limit, you could display your custom alert by overriding the multipleFilesMessageFileSizeErrorHandler
in SBUGroupChannelViewController
.
UI for message senders
A user can select multiple image or video files from their gallery. When the user selects both images and videos simultaneously, the image thumbnails are grouped together in the UI, while video files are shared individually.
Note: The files are sorted by the OS' image picker on the device.
If one of the files fails to send, the message is marked as failed
. As auto resend isn't supported for multiple files messages, add a resend()
option to the long-tab menu to allow the message sender to retry sending the message.
UI for recipients
For those who receive multiple files messages, image thumbnails are grouped together on the UI and the thumbnail of video files appears individually as well.
A short-tab on the image or video file can show the file preview and a download button for individual files. For a long tab, display menu that includes reaction emojis, a delete button, and a reply button.
Note: Only text messages and single file messages can be sent as a reply.
Open channel
There are currently four different types of file messages that users can send: image file, video file, audio file, and document file. These files can be shared with other participants in the channel by either directly taking a photo with the camera on a mobile device or uploading an image, video, audio, or document file from the sender’s mobile device.
Note : In order to use the file sharing feature, you must first create a channel and enable chat service. To learn how to allow users to chat in a channel, refer to Chat in an open channel.
Customize the UI for file sharing
You can customize the UI for file sharing using SBUMessageCellTheme
in the SBUTheme
, SBUStringSet
, and SBUIconSet
.
SBUMessageCellTheme
The following table shows customizable theme properties of file sharing.
Category | Property | Description |
---|---|---|
File message | fileIconBackgroundColor | The background color of the file icon. |
File message | fileIconColor | The color of the file icon. |
File message | fileMessageNameFont | The text font of the file message name element. |
File message | fileMessageLeftTextColor | The text color of the left side of a file message. |
File message | fileMessageRightTextColor | The text color of the right side of a file message. |
File message | fileMessagePlaceholderColor | The text color of a file message's placeholder. |
SBUStringSet
The following table shows a property of SBUStringSet
that can be modified to customize file sharing. The SBUStringSet
is a set of strings used to compose the screen. You need to modify the stringSet
values in advance if you want to make changes to the screen.
Property name | Description |
---|---|
Channel_Success_Download_file | A text for file save completion. |
Channel_Failure_Download_file | A text for file save failure. |
Channel_Failure_Open_file | A text for file open failure. |
SBUIconSet
The following table shows customizable file sharing icons.
Icon name | Image | Description |
---|---|---|
iconAdd | Add a file. | |
iconDocument | Select a file to send. | |
iconFileAudio | An audio file message. | |
iconFileDocument | A document file message. | |
iconGif | A | |
iconPlay | Play a video file message. |
Image compression
UIKit for iOS allows users to compress images when sending them to other users in the channel on a client app. By reducing the image size, they can send and receive image files faster and minimize the usage of data storage as well as the data usage.
The following table lists properties in the SBUGlobals
class that are related to image compression. These properties can be customized before you initialize UIKit or create a new channel.
Property | Type | Description |
---|---|---|
isImageCompressionEnabled | Bool | Determines whether to compress the image when sending an image file message. (Default: |
imageCompressionRate | CGFloat | The value of the compression rate to apply to the image. Acceptable values are 0.0 to 1.0, inclusive. (Default: |
imageResizingSize | CGSize | The value of the size dimensions to apply to the image. (Default: |
Note: To compress an image without changing the size dimensions, use the
imageCompressionRate
property. To resize the image, use theimageResizingSize
property.
Playing audio and video files
UIKit for iOS uses AVPlayerViewController
to play audio and video files. The files will play without audio when the user's device is on silent mode. However, in version 3.4.0 or later, the client app uses UIDocumentInteractionController
to play audio and video files with sound even when the user's device is on silent mode. By setting SBUGlobals.isAVPlayerAlwaysEnabled
to true
, you can still use AVPlayerViewController
in version 3.4.0 or later. The default value of the property is set to false
.