TikTok Open Platform SDK for iOS - Quickstart

Getting Started with the TikTok SDK for iOS

Requirements

TikTok iOS SDK requires iOS 9.3 and Xcode 4.5 or later.

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.

Step 2: Install the SDK

Via Cocoapods

Add the pod to your Podfile:

pod 'TikTokOpenSDK', '~> 2.0.0'

And then run:

pod install --repo-update

Via Manual Install

Download link for SDK and unzip the zip file, and you would find the SDK called TikTokOpenPlatformSDK.framework

Link Framework

  1. Copy or Drag the SDK into your Xcode Project. Select your Project in Project Navigator. Click "+" in TARGETS -> Build Phases -> Link Binary With Libraries, and then select TikTokOpenPlatformSDK.framework in your Project folder to add it.

  2. Add WebKit.framework and Security.framework.

  • WebKit.framework - It is used to gain authorization through web-view when TikTok is not installed.
  • Security.framework - Encryption and decryption library. We use this framework to ensure that communications are securely transmitted.
  1. Add Link Flag -ObjC in TARGETS->Build Settings->Other Linker Flags. Make sure the letter 'O' and 'C' are capitalized.

The correct configuration is shown below: 1_1_1

Step 3: Configure Xcode Project

Configure Info.plist

  1. In Xcode, right-click your project's Info.plist file and select Open As -> Source Code.
  2. Here are 3 keys need to configuration:
    1. LSApplicationQueriesSchemes: Use to Open TikTop App
    2. TikTokAppID: Use to config TikTok OpenSDK
    3. CFBundleURLTypes : Use TikTok App callback your App Insert the following XML snippet into the body of your file just before the final </dict> element.
<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>
  1. Replace $TikTokAppID with your App's Client Key

Note:

  • tiktokopensdk is used for authentication, while tiktoksharesdk is used for sharing.
  • snssdk1233, snssdk1180 are used to check if the TikTok application is installed.
  • The TikTok Open SDK auto-registers your Client Key when your App launches.

Make sure your app has access to Photo Library

Sharing pictures requires Photo Library access. Make sure a proper Privacy - Photo Library Usage Description is added in your Info.plist.

After the configuration, your Info.plist will look like the following. 1_3

Step 4: Connect App delegate

Connect App delegate You need to connect your AppDelegate class to the TiktokOpenPlatformApplicationDelegate.h To do this, add the following code to your AppDelegate.m file.

#import <TikTokOpenPlatformSDK/TiktokOpenPlatformApplicationDelegate.h>
@implementation TikTokOpenPlatformAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[TiktokOpenPlatformApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
        return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    
    if ([[TiktokOpenPlatformApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]
        ) {
        return YES;
    }    
    return NO;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if ([[TiktokOpenPlatformApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]) {
        return YES;
    }
    return NO;
}
    
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    if ([[TiktokOpenPlatformApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:nil annotation:nil]) {
        return YES;
    }
    return NO;
}
@end

API Instructions

TiktokOpenPlatformApplicationDelegate

AppType

/// Differentiate whether the app to be communicated is Chinese or international
typedef NS_ENUM(NSInteger, TikTokOpenPlatformAppType) {
    TikTokOpenPlatformAppTypeChina = 0, //!< Communicated is Chinese
    TikTokOpenPlatformAppTypeI18N, //!< Communicated is international
};

TikTokOpenPlatformAppType define the channel of you configuration. TikTokOpenPlatformSDK can communicated with 2 different APP. If you want to share to TikTok please use TikTokOpenPlatformAppTypeI18N.

Log Delegate

@protocol TikTokOpenPlatformLogDelegate <NSObject>

- (void)tiktokOnLog:(NSString *)logInfo;

@end

TikTok internal log in level ERROR or Warning will callback in this method.You need to register log delgate in TiktokOpenPlatformApplicationDelegate

Usage :

    [TiktokOpenPlatformApplicationDelegate sharedInstance].logDelegate = self; 

Check TikTok is installed :

- (BOOL)isAppInstalledWithAppType:(TikTokOpenPlatformAppType) appType;

Please pass appType as TikTokOpenPlatformAppTypeI18N to verify TikTok App Installed. if installed will return YES

TikTokOpenPlatformObjects

The definition of basic classes (Reuqest or Response) to SDK.