TemplateShareManager.m 4.98 KB
//
//  TemplateShareManager.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/10/20.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "TemplateShareManager.h"
#import "TemplateShareButton.h"

@implementation TemplateShareManager

static TemplateShareManager *shareManaager = nil;
+ (TemplateShareManager *)shareSingleton{
    @synchronized(self){
        if (shareManaager == nil) {
            shareManaager = [[TemplateShareManager alloc] init];
        }
    }
    return shareManaager;
}

#pragma mark 注册友盟分享以及配置信息
- (void)shareConfig
{
    [ShareSDK registerApp:@"134f952a9e004" activePlatforms:@[@(SSDKPlatformTypeSinaWeibo),
                                                             @(SSDKPlatformSubTypeWechatSession),
                                                             @(SSDKPlatformSubTypeWechatTimeline),
                                                             @(SSDKPlatformTypeQQ)]
                 onImport:^(SSDKPlatformType platformType)
     {
         switch (platformType)
         {
             case SSDKPlatformTypeWechat:
                 [ShareSDKConnector connectWeChat:[WXApi class]];
                 break;
             case SSDKPlatformTypeQQ:
                 [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
                 break;
             case SSDKPlatformTypeSinaWeibo:
                 [ShareSDKConnector connectWeibo:[WeiboSDK class]];
                 break;
             default:
                 break;
         }
     }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
     {
         
         switch (platformType)
         {
             case SSDKPlatformTypeSinaWeibo:
                 //设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
                 [appInfo SSDKSetupSinaWeiboByAppKey:@"604714517"
                                           appSecret:@"542573f3d166742a230634d5c2576157"
                                         redirectUri:@"https://api.weibo.com/oauth2/default.html"
                                            authType:SSDKAuthTypeBoth];
                 break;
             case SSDKPlatformTypeWechat:
                 [appInfo SSDKSetupWeChatByAppId:@"wx1eb184b8425c2503"
                                       appSecret:@"4d250e1ef3b7f5f1bc3579237fd4ee62"];
                 break;
             case SSDKPlatformTypeQQ:
                 [appInfo SSDKSetupQQByAppId:@"1105424006"
                                      appKey:@"EneqtYjiKSswk05g"
                                    authType:SSDKAuthTypeBoth];
                 break;
             default:
                 break;
         }
     }];
    
}

- (void)shareType:(TemplateShareButtonType)type shareImage:(id)shareImage shareTitle:(NSString *)shareTitle shareText:(NSString *)shareText shareUrl:(NSString *)shareUrl{

    //1、创建分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:shareText images:shareImage url:[NSURL URLWithString:shareUrl] title:shareTitle type:SSDKContentTypeAuto];
    
    //2、分享
    if (type == TemplateShareButtonTypeWeiXin){
        //微信
        [self startSharePlatform:SSDKPlatformTypeWechat parameters:shareParams];
        
    }
    else if (type == TemplateShareButtonTypePengYouQuan) {
        //朋友圈
        [self startSharePlatform:SSDKPlatformSubTypeWechatTimeline parameters:shareParams];
    }
    else if (type == TemplateShareButtonTypeXLWeiBo){
        //新浪微博
        [self startSharePlatform:SSDKPlatformTypeSinaWeibo parameters:shareParams];
        
    }
    else if (type == TemplateShareButtonTypeQQ){
        //qq
        [self startSharePlatform:SSDKPlatformTypeQQ parameters:shareParams];
        
    }
    else if (type == TemplateShareButtonTypeQQZone){
        //qq空间
        [self startSharePlatform:SSDKPlatformSubTypeQZone parameters:shareParams];
        
    }
    
}
- (void)startSharePlatform:(SSDKPlatformType)platform parameters:(NSMutableDictionary *)parameters{
    
    [ShareSDK share:platform parameters:parameters onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
        
        switch (state) {
            case SSDKResponseStateSuccess:
            {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:CustomStr(@"ShareSuccess") message:nil  delegate:nil cancelButtonTitle:CustomStr(@"Sure") otherButtonTitles:nil];
                [alertView show];
                break;
            }
            case SSDKResponseStateFail:
            {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:CustomStr(@"ShareFailure") message:[NSString stringWithFormat:@"%@",error] delegate:nil cancelButtonTitle:CustomStr(@"Sure") otherButtonTitles:nil];
                [alertView show];
                break;
            }
            default:
                break;
        }
    }];
}
@end