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

#import "TemplateShareManager.h"

@implementation TemplateShareManager
static TemplateShareManager *shareManager = nil;

+ (TemplateShareManager *)manager{
    @synchronized(self){
        if (shareManager == nil) {
            shareManager = [[TemplateShareManager alloc] init];
        }
    }
    return shareManager;
}

#pragma mark 注册ShareSDK分享以及配置信息
- (void)shareConfig {

    [ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
        //QQ
//        [platformsRegister setupQQWithAppId:@"1105424006" appkey:@"EneqtYjiKSswk05g"];
        [platformsRegister setupQQWithAppId:@"1105424006" appkey:@"EneqtYjiKSswk05g" enableUniversalLink:NO universalLink:@"https://mjjai.share2dlink.com/"];
        //微信
//        [platformsRegister setupWeChatWithAppId:@"wx1eb184b8425c2503" appSecret:@"4d250e1ef3b7f5f1bc3579237fd4ee62"];
        [platformsRegister setupWeChatWithAppId:@"wx1eb184b8425c2503" appSecret:@"4d250e1ef3b7f5f1bc3579237fd4ee62" universalLink:@"https://mjjai.share2dlink.com/"];
        //新浪
        [platformsRegister setupSinaWeiboWithAppkey:@"604714517" appSecret:@"542573f3d166742a230634d5c2576157" redirectUrl:@"https://api.weibo.com/oauth2/default.html"];
        
    }];
    
}

- (void)shareImage:(NSString *)image title:(NSString *)title text:(NSString *)text url:(NSString *)url controller:(UIViewController *)controller {
    NSArray *imageArray = nil;
    if (!image||[image isEqualToString:@""]) {
        imageArray = @[[UIImage imageNamed:@"cnlive_zhouxin_icon"]];
    } else {
        imageArray = @[image];
    }
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:text images:imageArray url:[NSURL URLWithString:url?url:@"http://app.scio.gov.cn/gxbShare.html"] title:title type:SSDKContentTypeWebPage];
    NSArray *items = @[
                       @(SSDKPlatformSubTypeWechatSession),
                       @(SSDKPlatformSubTypeWechatTimeline),
                       @(SSDKPlatformTypeQQ),
                       @(SSDKPlatformTypeSinaWeibo)
                       ];
    
    [ShareSDK showShareActionSheet:nil customItems:items shareParams:shareParams sheetConfiguration:nil onStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
        switch (state) {
            case SSDKResponseStateSuccess:
            {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:CustomStr(@"ShareSuccess") message:nil preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *action1 = [UIAlertAction actionWithTitle:CustomStr(@"Sure") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    NSLog(@"点击了确定,进入确定的事件");
                    
                }];
                [alert addAction:action1];
                [controller presentViewController:alert animated:YES completion:nil];
                break;
            }
            case SSDKResponseStateFail:
            {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:CustomStr(@"ShareFailure") message:nil preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *action1 = [UIAlertAction actionWithTitle:CustomStr(@"Sure") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    NSLog(@"点击了确定,进入确定的事件");
                    
                }];
                [alert addAction:action1];
                [controller presentViewController:alert animated:YES completion:nil];
                break;
            }
            default:
                break;
        }
        
    }];
    
}

@end