TikTok iOS SDK Swift— Videos, Photos Sharing in TikTok from your iOS app

Mohammad Mahmudul Hasan
3 min readDec 4, 2021

Video Kit allows users to share videos and photos from iOS app to TikTok.

Now there is a SDK to share Videos, Photos from iOS to TikTok. This SDK include Login Kit, Sound Kit, sharing videos etc. In this tutorial we will cover Photos and Videos share only. Let’s start.

Step 1: Configure TikTok App Settings for iOS

Go to TikTok Developer App Registration Page to create your app. After approval, you will get the Client Key and Client Secret. Which is must to implement this SDK in iOS.

Step 2: Install the SDK

Add the pod to your Podfile:

pod 'TikTokOpenSDK', '~> 5.0.0'

And then run:

pod install

Step 3: Configure Xcode Project

  1. Update Info.plist just like below
  2. LSApplicationQueriesSchemes: Use to Open TikTop App
  3. TikTokAppID: Use to config TikTok OpenSDK
  4. CFBundleURLTypes : Use TikTok App callback your App
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tiktokopensdk</string>
<string>tiktoksharesdk</string>
<string>snssdk1180</string>
<string>snssdk1233</string>
</array>
<key>TikTokAppID</key>
<string>$TikTokAppID</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>$TikTokAppID</string>
</array>
</dict>
</array>

Don’t forget to replace $TikTokAppID with your App's Client Key

Step 4: Update AppDelegate and SceneDelegate

Update AppDelegate.h like below.

import TikTokOpenSDK
@main
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
TikTokOpenSDKApplicationDelegate.sharedInstance().logDelegate = self
TikTokOpenSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)return true}func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

guard let sourceApplication = options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
let annotation = options[UIApplication.OpenURLOptionsKey.annotation] else {
return false
}

if TikTokOpenSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: sourceApplication, annotation: annotation) {
return true
}
return false
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if TikTokOpenSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation) {
return true
}
return false
}

func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
if TikTokOpenSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: nil, annotation: "") {
return true
}
return false
}
}

If there is a SceneDelegate.h, you will need to add the following function to your SceneDelegate.h file.

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
_ = appDelegate.application(UIApplication.shared, open: url, options: [:])
}
}
}

Step 5: TikTokOpenSDKLogDelegate

ERROR or Warning will callback in this method.

func onLog(_ logInfo: String) {print(logInfo)}

Step 6: Implement Video Kit Functionality

Video Kit allows users to share videos and photos from your app to TikTok. Make sure your app has access to Photo Library.

private class func shareToTikTok(isVideo: Bool, asset: PHAsset) {let isInstalled = TikTokOpenSDKApplicationDelegate.sharedInstance().isAppInstalled()if (isInstalled) {let request = TikTokOpenSDKShareRequest()request.mediaType = isVideo ? TikTokOpenSDKShareMediaType.video : TikTokOpenSDKShareMediaType.imagevar mediaLocalIdentifiers: [String] = []mediaLocalIdentifiers.append(asset.localIdentifier)request.localIdentifiers = mediaLocalIdentifiersrequest.hashtag = "ERSocialShareManager"request.send(completionBlock: { resp -> Void inprint(resp)})}}

Conclusion

And finally we are done. Thank you very much for reading. Happy coding :)

--

--

Mohammad Mahmudul Hasan

A learner, constantly striving to learn new technologies and look the ways to be better in this rapidly changing industry.