登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

抖音分享和授权(iOS) [复制链接]

2019-4-2 17:23
shareiOS 阅读:481 评论:0 赞:0
Tag:  

准备工作

  • 注册appkey (抖音开放平台
  • 集成sharesdk(下载地址
  • Xcode配置:urlScheme为注册的appkey, 白名单:douyinsharesdk ,douyinopensdk

业务代码

初始化

#import <ShareSDK/ShareSDK.h>
[ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
    //抖音
    [platformsRegister setupDouyinByAppKey:@"app_key" appSecret:@"app_secret"];
}];

分享

可以分享图片,相册图片,单个视频,多个视频

分享图片

// 通用参数设置----图片分享可以使用相册地址、沙盒路径、网络图片地址
NSString *imageURL = @"http://img.hb.aicdn.com/28a4962c297205e0868cdb45bb527e2bc5319f08f019-l7N1A3_fw658";
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters SSDKSetupShareParamsByText:nil
                                images:@[imageURL]
                                   url:nil
                                 title:nil
                                  type:SSDKContentTypeImage];
                                  
[ShareSDK share:SSDKPlatformTypeDouyin parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
    if (state == SSDKResponseStateSuccess) {
        NSLog(@"成功!");
    }else{
        NSLog(@"%@",error);
    }
}];

分享视频

// 通用参数设置----视频分享可以使用相册地址、沙盒路径,不支持网络视频,如果使用网络视频请先下载放到沙盒目录下或相册里
    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);
        }
    }];

分享多个视频


 // 平台定制----只能使用相册且使用相册标识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);
        }
    }];
分享到:
我来说两句
facelist
您需要登录后才可以评论 登录 | 立即注册
所有评论(0)
关闭

每日头条

通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| 广东互联网违法和不良信息举报中心|中国互联网举报中心|Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

返回顶部