Contents

upload(_:)

Uploads a file to the RCS content server.

Declaration

final func upload(_ uploadRequest: RCSService.FileUploadRequest) async throws -> RCSService.FileUploadRequest.Metadata

Parameters

  • uploadRequest:

    A Fileuploadrequest instance that describes the file to upload and an optional thumbnail.

Return Value

A RCSService.FileUploadRequest.Metadata instance that contains information about the uploaded file.

Discussion

Sending a file to a recipient over RCS is a two-step process:

  1. Call upload(_:) to upload the file to the carrier.

  2. Send a message of type RCSMessage.FileTransfer to the recipient, using metadata returned from the upload step.

The following example shows this process:

let service = TelephonyMessagingSession.shared.rcsService

let cellularServices = try TelephonyMessagingSession.shared.cellularServices
let cellularServiceID = cellularServices[0].id

guard service.isViable(for: cellularServiceID) else { return }
guard let uploadURL = URL(string: SAMPLE_UPLOAD_FILE_PATH) else { return }

// Upload file.
let request = RCSService.FileUploadRequest(cellularServiceID: cellularServiceID,
                                                 fileURL: uploadURL,
                                                 contentType: UTType.plainText)
let uploadMetadata = try await service.upload(request)

// Send file transfer message to recipient handle, using upload metadata.
try await service.sendMessage(RCSMessage.FileTransfer(fileMetadata: uploadMetadata.fileMetadata),
                    to: RCSHandle.phoneNumber(SAMPLE_PHONE_NUMBER)!,
                    using: cellularServiceID,
                    messageID: RCSMessageID(rawValue: SAMPLE_RCS_MESSAGE_ID))

See Also

Transferring files