iOS Sharing Documentation

Introduction

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

Preparation

Before you start sharing, you need to complete all of the configurations listed in Getting Started with the TikTok SDK for iOS. You can complete the sharing step by step:

Step 1 : Import Header

Import TikTokOpenSDKShare.h

#import <TikTokOpenSDK/TikTokOpenSDKShare.h>

Step 2 : Construct a Share Request

Construct a share request.

TikTokOpenPlatformShareRequest *req = [[TikTokOpenPlatformShareRequest alloc] init];

Step 3 : Required Parameters

Set the shared resource type. Currently we support images and videos.

req.mediaType = BDOpenPlatformShareMediaTypeImage;
//Or
req.mediaType = BDOpenPlatformShareMediaTypeVideo;

Set share localIdentifiers as PHAsset.

e.g

NSMutableArray<NSString *> *mediaLocalIdentifiers = [NSMutableArray array];
for (PHAsset *asset in self.selectedAssets) {
    [mediaLocalIdentifiers addObject:asset.localIdentifier];
}
req.localIdentifiers = [mediaLocalIdentifiers copy];

Note:

  • The aspect ratio of the images or videos should between: [1/2.2, 2.2]
  • If mediaType is Image:
    • The number of images should be more than one and up to 12.
  • If mediaType is Video:
    • Total video duration should be longer than 1 seconds.
    • No more than 12 videos can be shared
    • Videos with brand logo or watermark will lead to the videos being deleted or the respective accounts disabled. Make sure your application shares content without a watermark.

Step 4 : Optional Parameters

Hashtag (waiting for release)

To associate your video with a hashtag, set the hashtag property on the request.

req.hashtag = @"agechallenge";

Note: But now this feature is not yet released, and passing in this parameter will be ignored.

State

You can customize a string to identify a share. The same state will be present in the respond. You can bind you information with this ShareID.

req.state = @"a47e57c6c559acb88a9569da66ee5f65e0f779c9";

Step 5 : Send Share Request

Call -[TikTokOpenSDKAuthRequest sendShareRequestWithCompleteBlock:] method to send the share request .

It will open the TikTok app and publish the content. Users can stay in TikTok or go back to your App after sharing.

If the user goes back to your app, you can receive a callback in CompleteBlock

When any error happens, the response will have an error code with the following mapping:

BDOpenPlatformErrorCodeerrorCodeDescription
BDOpenPlatformSuccess0shared success
BDOpenPlatformErrorCodeCommon-1Common error type e.g. network error
BDOpenPlatformErrorCodeUserCanceled-2User Canceled share in TikTok
BDOpenPlatformErrorCodeSendFailed-3User pubilsh content Failed
BDOpenPlatformErrorCodeAuthDenied-4Auth Denied,
BDOpenPlatformErrorCodeUnsupported-5Unsupported

If the error code does not make it easy for you to locate a specific error, you can use 'respond.shareState` for detail message. SDK version need 2.0.8 or higher.

The following map defines the Sharing state and specific issues.

BDOpenPlatformShareRespStatevalueDescription
BDOpenPlatformShareRespStateSuccess20000Success
BDOpenPlatformShareRespStateUnknownError20001Unknown or current SDK version unclassified error
BDOpenPlatformShareRespStateParamValidError20002Params parsing error, media resource type difference you pass
BDOpenPlatformShareRespStateSharePermissionDenied20003Not enough permissions to operation.
BDOpenPlatformShareRespStateUserNotLogin20004User not login
BDOpenPlatformShareRespStateNotHavePhotoLibraryPermission20005TikTok has no album permissions
BDOpenPlatformShareRespStateNetworkError20006TikTok Network error
BDOpenPlatformShareRespStateVideoTimeLimitError20007Video length doesn't meet requirements
BDOpenPlatformShareRespStatePhotoResolutionError20008Photo doesn't meet requirements
BDOpenPlatformShareRespTimeStampError20009Timestamp check failed
BDOpenPlatformShareRespStateHandleMediaError20010Processing photo resources faild
BDOpenPlatformShareRespStateVideoResolutionError20011Video resolution doesn't meet requirements
BDOpenPlatformShareRespStateVideoFormatError20012Video format is not supported
BDOpenPlatformShareRespStateCancel20013Sharing canceled
BDOpenPlatformShareRespStateHaveUploadingTask20014Another video is currently uploading
BDOpenPlatformShareRespStateSaveAsDraft20015Users store shared content for draft or user accounts are not allowed to post videos
BDOpenPlatformShareRespStatePublishFailed20016Post share content failed
BDOpenPlatformShareRespStateMediaInIcloudError21001Downloading from iCloud faild
BDOpenPlatformShareRespStateParamsParsingError21002Internal params parsing error
BDOpenPlatformShareRespStateGetMediaError21003Media resources do not exist