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

Step 1: Configure TikTok App Settings for iOS

Step 2: Install the SDK

pod 'TikTokOpenSDK', '~> 5.0.0'
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>

Step 4: Update AppDelegate and SceneDelegate

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
}
}
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

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

Step 6: Implement Video Kit Functionality

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

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Understanding Task Modifier in Swift for iOS 15

Adding multiple projects in one Xcode project

📈 Unit Testing in Swift: Introduction

Best Video Downloading app for iPhone and iPad — 2020

How to Improve the Validation in Your SwiftUI App Using ValidatedPropertyKit

Swift Programming Tutorial: Loops

Getting Started with RealityKit: Video Materials

TV and RealityKit logos

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mohammad Mahmudul Hasan

Mohammad Mahmudul Hasan

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

More from Medium

Asynchronous tasks in iOS (Swift)

Avoid “Keyboard hiding TextField” Problem in iOS using Protocol

How to build iOS Authentication with Firebase Part II Sign Up User 2022

How to implement GraphQL in your iOS project.