swift技术爱好者-swift技术论坛

swift技术交流分享

swift 集成最新版的ShareSDK

2019-8-27 admin 第三方分享

ShareSDK是一个第三方分享模块集成很多了分享功能。

第一:Pod集成

# 主模块(必须)
pod 'mob_sharesdk'

# UI模块(非必须,需要用到ShareSDK提供的分享菜单栏和分享编辑页面需要以下1行)
pod 'mob_sharesdk/ShareSDKUI'

# 平台SDK模块(对照一下平台,需要的加上。如果只需要QQ、微信、新浪微博,只需要以下3行)
pod 'mob_sharesdk/ShareSDKPlatforms/QQ'
pod 'mob_sharesdk/ShareSDKPlatforms/SinaWeibo'
pod 'mob_sharesdk/ShareSDKPlatforms/WeChat'   //(微信sdk不带支付的命令)
# pod 'mob_sharesdk/ShareSDKPlatforms/WeChatFull' //(微信sdk带支付的命令,和上面不带支付的不能共存,只能选择一个)

#需要精简版QQ,微信,微博的可以加这3个命令(精简版去掉了这3个平台的原生SDK)
pod 'mob_sharesdk/ShareSDKPlatforms/QQ_Lite'
pod 'mob_sharesdk/ShareSDKPlatforms/SinaWeibo_Lite'
pod 'mob_sharesdk/ShareSDKPlatforms/WeChat_Lite'


第二步:初始化
在appdelegate中初始化SDK

     ShareSDK.registPlatforms { (devrgister) in
            devrgister?.setupWeChat(withAppId: "", appSecret: "")
            devrgister?.setupQQ(withAppId: "", appkey: "")
        }
这里的APPID APPKEY按需填写
桥接文件(ShareSDK-Bridging-Header.h)导入OC文件头

 #import <ShareSDK/ShareSDK.h>
 #import <ShareSDKUI/ShareSDK+SSUI.h>
 #import <ShareSDKConnector/ShareSDKConnector.h>


第三步:调用分享代码


// 1.创建分享参数
        let shareParames = NSMutableDictionary()
        shareParames.ssdkSetupShareParams(byText: "分享内容",
                                           images : UIImage(named: "shareImg.png"),
                                              url : NSURL(string:"http://mob.com") as URL!,
                                            title : "分享标题",
                                             type : SSDKContentType.image)

        //2.进行分享
        ShareSDK.share(SSDKPlatformType.typeSinaWeibo, parameters: shareParames) { (state : SSDKResponseState, nil, entity : SSDKContentEntity?, error :Error?) in

            switch state{

            case SSDKResponseState.success: print("分享成功")
            case SSDKResponseState.fail:    print("授权失败,错误描述:\(error)")
            case SSDKResponseState.cancel:  print("操作取消")

            default:
                break
            }

        }