How to Share a Video from your app on TikTok Using Swift

Sotiris Kaniras
ITNEXT
Published in
4 min readOct 20, 2023

--

I recently had to implement a video sharing feature in our app, and even though it’s fairly easy to share on Instagram and Snapchat, I found it quite confusing to use TikTok’s share API.

So, for all the Swift developers out there who are scratching their heads over this, I decided to write a quick, step-by-step guide to make the process smoother.

Before we code

You’ll need a valid TikTok Developer account. This is quite easy and TikTok did a good job documenting it, so we are not going to delve into that here. All you need to know, is that we’re going to be using the Share Kit library.

Once you create your account, and later an app on TikTok, you’ll have access to the Client Key. Go ahead and copy and paste it to your Info.plist file, under the key TikTokClientKey.

Next, add the necessary Queried URL Schemes:

  1. tiktoksharesdk
  2. snssdk1233
  3. snssdk1180

Dependency

Here, we’ll be using SPM (Swift Package Manager) to install the library. Go to File -> Add Package Dependencies… and paste https://github.com/tiktok/tiktok-opensdk-ios. You’ll get the list of libraries TikTok offers; for our purpose, we only need TikTokOpenShareSDK.

Universal links

The last thing we need before we jump into the actual coding, is to set up dynamic links. TikTok requires we register a URL so they can use it to redirect from TikTok to our app when needed.

While using universal links can be a daunting process, Firebase offers a solution that simplifies it greatly.

Firebase announced that they’ll be shutting down Dynamic Links on August 25, 2025. Depending on when you are reading this, we have quite some time until then, but if you want to be extra sure, you probably will want to use another service.

Go to Firebase -> Dynamic Links and add a new one. Choose a URL suffix, doesn’t matter what you write, but this is what you’ll be using with TikTok. Hit Next, and add a Deep link URL like https://myapp.page.link/tiktok and a name. Lastly, finish up by setting up the Apple behaviour, like so:

Your new dynamic link is now ready to use. Go to your TikTok Developer account, enable the Login Kit & Share Kit as per documentation and add the new URL on Login Kit.

Unfortunately, you cannot test it right away. You first need to submit for review and get approved. It usually takes 1–2 days.

The code

At last, to the interesting stuff! Create a new Swift file and name it TikTokShareService, or something like that.

import Foundation
import TikTokOpenShareSDK
import Photos

class TikTokShareService {
private var shareRequest: TikTokShareRequest?
private let redirectURI = "https://myapp.page.link/tikTokRedirect"
private var localVideoIdentifier: String?

// --------------------------

func uploadVideo(localVideoURL: URL, completion: @escaping (Bool) -> Void) {
PHPhotoLibrary.requestAuthorization { [weak self] status in
switch status {
case .authorized:
PHPhotoLibrary.shared().performChanges({
let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: localVideoURL)
let assetPlaceholder = createAssetRequest?.placeholderForCreatedAsset

self?.localVideoIdentifier = assetPlaceholder?.localIdentifier
}) { [weak self] success, error in
guard let localVideoIdentifier = self?.localVideoIdentifier else { return }
guard let redirectURI = self?.redirectURI else { return }

self?.shareRequest = TikTokShareRequest(localIdentifiers: [localVideoIdentifier],
mediaType: .video,
redirectURI: redirectURI)

DispatchQueue.main.async {
self?.shareRequest?.send()
completion(true)
}
}
default:
completion(false)
}
}
}
}

A lot of stuff is happening here, so let's go step by step to explain it:

  1. We import the TikTok SDK and the Photos library, because we have to save the video to the iPhone’s Photo Library before we can send it to TikTok.
  2. We create 3 variables;
    shareRequest, which will be used to create the send request.
    redirectURI, the Dynamic Link from Firebase from the previous step.
    localVideoIdentifier, which represents the video file we want to share.
  3. The uploadVideo function. Here we pass localVideoURL which is the local path of the video file we want to share. We use PHPhotoLibrary to save the video to the iPhone’s Photo Library and retrieve its id (assetPlaceholder?.localIdentifier), so we can give it to TikTok, and TikTok can use it to create a draft with that video.
  4. If all of that was successful, we initialise shareRequest and call send().

After that, the TikTok app will open automatically with a draft using the selected video, for the user to post.

Final thoughts

Even though it's not the most difficult thing for a software engineer to achieve, I can say that using TikTok’s share API is much harder than the implementations of Instagram and Snapchat. Even the fact that you have to wait for your app to be approved by TikTok, in order to be able to test your implementation, is a big fail for me!

In any case, I hope you found this guide helpful so you can make your app go viral on TikTok! 😁

--

--

Full-stack iOS Engineer & Co-Founder of nup nupapp.com and UNIpad unipad.gr | Passionate iOS dev | Chess & Netflix addict | Musk believer | Dev on wheels ♿️