抖音的分享和受權(iOS)

準備工做
註冊appkey (抖音開放平臺)
集成sharesdk(下載地址)
Xcode配置:urlScheme爲註冊的appkey, 白名單:douyinsharesdk ,douyinopensdk
業務代碼
初始化網絡

import <ShareSDK/ShareSDK.h>

[ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {app

//抖音
[platformsRegister setupDouyinByAppKey:@"app_key" appSecret:@"app_secret"];

}];
分享
能夠分享圖片,相冊圖片,單個視頻,多個視頻async

分享圖片ide

// 通用參數設置----圖片分享可使用相冊地址、沙盒路徑、網絡圖片地址
NSString *imageURL = @"http://img.hb.aicdn.com/28a4962c297205e0868cdb45bb527e2bc5319f08f019-l7N1A3_fw658";
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters SSDKSetupShareParamsByText:nilurl

images:@[imageURL]
                               url:nil
                             title:nil
                              type:SSDKContentTypeImage];

[ShareSDK share:SSDKPlatformTypeDouyin parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary userData, SSDKContentEntity contentEntity, NSError *error) {spa

if (state == SSDKResponseStateSuccess) {
    NSLog(@"成功!");
}else{
    NSLog(@"%@",error);
}

}];
分享視頻code

// 通用參數設置----視頻分享可使用相冊地址、沙盒路徑,不支持網絡視頻,若是使用網絡視頻請先下載放到沙盒目錄下或相冊裏orm

NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"cat" ofType:@"mp4"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters SSDKSetupShareParamsByText:nil
                                images:nil
                                   url:[NSURL URLWithString:videoPath]
                                 title:nil
                                  type:SSDKContentTypeVideo];
                                  
[ShareSDK share:SSDKPlatformTypeDouyin parameters:parameters onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
    if (state == SSDKResponseStateSuccess) {
        NSLog(@"成功!");
    }else{
        NSLog(@"%@",error);
    }
}];

分享多個視頻cdn

// 平臺定製----只能使用相冊且使用相冊標識localIdentifier視頻

__block NSMutableArray *assetLocalIds = [NSMutableArray array];
__weak typeof(self) weakSelf = self;

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    
    NSURL *url_1 = [[NSBundle mainBundle] URLForResource:@"cat" withExtension:@"mp4"];
    NSURL *url_2 = [[NSBundle mainBundle] URLForResource:@"cat" withExtension:@"mp4"];
    
    PHAssetChangeRequest *req_1 = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:url_1];
    NSString *localId_1 = req_1.placeholderForCreatedAsset.localIdentifier;
    [assetLocalIds addObject:localId_1];
    
    PHAssetChangeRequest *req_2 = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:url_2];
    NSString *localId_2 = req_2.placeholderForCreatedAsset.localIdentifier;
    [assetLocalIds addObject:localId_2];
    
} completionHandler:^(BOOL success, NSError * _Nullable error) {
    if (success) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
            [parameters SSDKSetupDouyinParamesByAssetLocalIds:assetLocalIds type:SSDKContentTypeVideo];
            
            [ShareSDK share:SSDKPlatformTypeDouyin parameters:parameters onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
                if (state == SSDKResponseStateSuccess) {
                    NSLog(@"成功!");
                }else{
                    NSLog(@"%@",error);
                }
            }];
        });
    }
}];

受權
[ShareSDK authorize:SSDKPlatformTypeDouyin settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser user, NSError error) {

if (state == SSDKResponseStateSuccess)
    {
        NSLog(@"%@",[user.credential rawData]);
        NSLog(@"%@",user.rawData);
       
    }
    else
    {
        NSLog(@"%@",error);
    }
}];
相關文章
相關標籤/搜索