Sharing allows users to share videos and photos from your app to TikTok. Make sure your app has access to Photo Library.
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:
Import TikTokOpenPlatformShareRequest.h
#import <TikTokOpenPlatformSDK/TikTokOpenPlatformShareRequest.h>
Construct a share request with type TikTokOpenPlatformAppTypeI18N
.
TikTokOpenPlatformShareRequest *req = [[TikTokOpenPlatformShareRequest alloc] initWithAppType:TikTokOpenPlatformAppTypeI18N];
Please use designated initializer -[TikTokOpenPlatformShareRequest initWithAppType:]
. The initializer method-TikTokOpenPlatformShareRequest init is unavailable.
Set the shared resource type. Currently we support images and videos.
req.mediaType = TiktokOpenPlatformShareMediaTypeImage;
//Or
req.mediaType = TiktokOpenPlatformShareMediaTypeVideo;
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.
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";
Call -[TikTokOpenPlatformShareRequest 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:
TiktokOpenPlatformErrorCode | errorCode | Description |
---|---|---|
0 | TiktokOpenPlatformSuccess | shared success |
TiktokOpenPlatformErrorCodeCommon | -1 | Common error type e.g. network error |
TiktokOpenPlatformErrorCodeUserCanceled | -2 | User Canceled share in TikTok |
TiktokOpenPlatformErrorCodeSendFailed | -3 | User pubilsh content Failed |
TiktokOpenPlatformErrorCodeAuthDenied | -4 | Auth Denied, |
TiktokOpenPlatformErrorCodeUnsupported | -5 | Unsupported |
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.
TiktokShareRespState | value | 描述 |
---|---|---|
TiktokShareRespStateSuccess | 20000 | Success |
TiktokShareRespStateUnknownError | 20001 | Unknown or current SDK version unclassified error |
TiktokShareRespStateParamValidError | 20002 | Params parsing error, media resource type difference you pass |
TiktokShareRespStateSharePermissionDenied | 20003 | Not enough permissions to operation. |
TiktokShareRespStateUserNotLogin | 20004 | User not login |
TiktokShareRespStateNotHavePhotoLibraryPermission | 20005 | TikTok has no album permissions |
TiktokShareRespStateNetworkError | 20006 | TikTok Network error |
TiktokShareRespStateVideoTimeLimitError | 20007 | Video length doesn't meet requirements |
TiktokShareRespStatePhotoResolutionError | 20008 | Photo doesn't meet requirements |
TiktokShareRespTimeStampError | 20009 | Timestamp check failed |
TiktokShareRespStateHandleMediaError | 20010 | Processing photo resources faild |
TiktokShareRespStateVideoResolutionError | 20011 | Video resolution doesn't meet requirements |
TiktokShareRespStateVideoFormatError | 20012 | Video format is not supported |
TiktokShareRespStateCancel | 20013 | Sharing canceled |
TiktokShareRespStateHaveUploadingTask | 20014 | Another video is currently uploading |
TiktokShareRespStateSaveAsDraft | 20015 | Users store shared content for draft or user accounts are not allowed to post videos |
TiktokShareRespStatePublishFailed | 20016 | Post share content failed |
TiktokShareRespStateMediaInIcloudError | 21001 | Downloading from iCloud faild |
TiktokShareRespStateParamsParsingError | 21002 | Internal params parsing error |
TiktokShareRespStateGetMediaError | 21003 | Media resources do not exist |