GithubHelp home page GithubHelp logo

basl12 / tiktok-opensdk-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tiktok/tiktok-opensdk-ios

0.0 0.0 0.0 1.17 MB

The TikTok OpenSDK features Login Kit and Share Kit which allow your users to log in using their TikTok account and share content from your app to TikTok.

Home Page: https://developers.tiktok.com

License: Other

Ruby 3.00% C 0.10% Swift 96.90%

tiktok-opensdk-ios's Introduction

TikTok OpenSDK for iOS

Introduction

TikTok OpenSDK is a framework that enables your users to log into your app with their TikTok accounts and share images and videos to TikTok. This SDK is available for download through Swift Package Manager and Cocoapods.

Getting Started

Minimum iOS version is 11.0 and minimum XCode version is 9.0. See iOS Quickstart for more details.

Developer Portal Application

Sign up for a developer account in our Developer Portal. Upon application approval, the Developer Portal will provide you with a Client Key and Client Secret. See how to register your app here. Before proceeding, make sure to add the Login Kit and/or Share Kit to your app by navigating to the Manage apps page, and clicking + Add products in your developer portal account.

Install the SDK

Swift Package Manager

Add the library to your XCode project as a Swift Package:

  1. Click File -> Add Packages...
  2. Paste the repository URL: https://github.com/tiktok/tiktok-opensdk-ios
  3. Select Dependency Rule -> Up to Next Major Version and input the major version you want (i.e. 2.2.0)
  4. Select Add to Project -> Your project
  5. Click Copy Dependency and select the libraries you need (TikTokOpenAuthSDK, TikTokOpenSDKCore, TikTokOpenShareSDK)

Cocoapods

  1. Add the following to your Podfile
pod 'TikTokOpenSDKCore'
pod 'TikTokOpenAuthSDK'
pod 'TikTokOpenShareSDK'
  1. Run pod install --repo-update

Configure Your XCode Project

  1. Open your Info.plist file and add/update the following keys.
    • Add the following values to LSApplicationQueriesSchemes:
      • tiktokopensdk for Login Kit
      • tiktoksharesdk for Share Kit
      • snssdk1233 and snssdk1180 to check if TikTok is installed on your device.
    • Add the key TikTokClientKey with your apps Client Key as the value.
    • Add your apps Client Key to CFBundleURLSchemes.
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>tiktokopensdk</string>
    <string>tiktoksharesdk</string>
    <string>snssdk1180</string>
    <string>snssdk1233</string>
</array>
<key>TikTokClientKey</key>
<string>$TikTokClientKey</string>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>$TikTokClientKey</string>
    </array>
  </dict>
</array>
  1. Add the following code to your app's AppDelegate:
import TikTokOpenSDKCore

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ app: UIApplication,open url: URL, 
                     options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        if TikTokURLHandler.handleOpenURL(url) {
            return true
        }
        return false
    }
        
    func application(_ application: UIApplication, 
                     continue userActivity: NSUserActivity, 
                     restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
            if TikTokURLHandler.handleOpenURL(userActivity.webpageURL) {
                return true
            }
        }
        return false
    }
    
}
  1. Add the following code to your app's SceneDelegate file if it has one:
import TikTokOpenSDKCore

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    func scene(_ scene: UIScene, 
               openURLContexts URLContexts: Set<UIOpenURLContext>) {
        if TikTokURLHandler.handleOpenURL(URLContexts.first?.url) {
            return
        }
    }

}

Login Kit Usage

Login Kit functionality depends on the TikTokOpenSDKCore and TikTokOpenAuthSDK libraries, so be sure to select these when adding the package or cocoapods. The following code snippet shows how to create an authorization request and handle the response. See Login Kit for iOS for more details.

import TikTokOpenAuthSDK

let authRequest = TikTokAuthRequest(scopes: ["user.info.basic"], redirectURI: "https://www.example.com/path")
authRequest.send { response in
    let authResponse = response as? TikTokAuthResponse else { return }
    if authResponse.errorCode == .noError {
        print("Auth code: \(authResponse.code)")
    } else {
       print("Authorization Failed! 
             Error: \(authResponse.error ?? "") 
             Error Description: \(authResponse.errorDescription ?? ""))
    }
}

Your app is responsible for maintaining a strong reference to the request in order to receive the response callback. You can discard it when you are done with the response.

Share Kit Usage

Share Kit functionality depends on the TikTokOpenSDKCore and TikTokOpenShareSDK libraries, so be sure to select these when adding the package or cocoapods. The following code snippet shows how to create a share request and handle the response. See Share Kit for iOS for more details.

import TikTokOpenShareSDK

let shareRequest = TikTokShareRequest(localIdentifiers: [...], mediaType: .video, redirectURI: "https://www.example.com/path")
shareRequest.send { response in
    let shareResponse = response as? TikTokShareResponse else { return }
    if shareResponse.errorCode == .noError {
        print("Share succeeded!")
    } else {
        print("Share Failed! 
               Error Code: \(shareResponse.errorCode.rawValue) 
               Error Message: \(shareResponse.errorMessage ?? "") 
               Share State: \(shareResponse.shareState)")
    }
}

Your app is responsible for maintaining a strong reference to the request in order to receive the response callback. You can discard it when you are done with the response.

Demos

Minimum iOS version for the demo apps is iOS 14.0 for ShareDemo and iOS 12.0 for LoginDemo.

  1. Open LoginDemo/TikTokLoginDemo.xcodeproj or ShareDemo/TikTokShareDemo.xcodeproj.
  2. In order to run the demos on a physical iOS device, you will need a working universal link, and a provisioning profile with the Associated Domains capability. Import your provisioning profile, update the bundle ID, and add your universal link domain to the Associated Domains section. If you are running the LoginDemo, make sure you have added your universal link to the Redirect URI portion of the Login Kit section in the developer portal.
  3. Open the Info.plist file as source code and replace the uses of ${TikTokClientKey} with your own client key from the developer portal.
  4. Run the project to view the kit in action.

License

This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.

tiktok-opensdk-ios's People

Contributors

nickdnk avatar stephen-boyle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.