ios新知识iOS-swiftios

IOS(swift)-社交媒体 ·第三方ShareSDK分享

2015-01-18  本文已影响1780人  俊瑶先森
需求:

使用第三方分享shareSDK

分享.png
第三方shareSDK,以微博为例。

1、登陆http://mob.com 并进入开发者后台,添加一个应用,获得App Key和App Secret。

2、登陆新浪微博开发者平台http://open.weibo.com ,添加应用,获得App Key和App Secret。

3.进入http://sharesdk.mob.com/Download -ShareSDK For iOS专用快速集成组件,下载你所需要的社交平台framework:

下载需要的SDK

4、将下载的SDK解压后导入工程中,勾选”Copy items if needed”:

导入

5、添加依赖库:

添加依赖.jpg
SystemConfiguration.framework
QuartzCore.framework
CoreTelephony.framework
libicucore.dylib
libz.1.2.5.dylib
Security.framework```

6、新建Header File,并建立桥接:

![新建文件](http:https://img.haomeiwen.com/i151218/c5846fbf748e1841.png)


![桥接](http:https://img.haomeiwen.com/i151218/45c08d167ad8246b.png)

7、打开桥接文件(TEST-Bridging-Header.h)导入文件头:

import "ShareSDK/ShareSDK.h"


8、在Appdelegate.Swift初始化SDK和第三方平台:
```
        ShareSDK.registerApp("ShareSDKAppKey")
       //新浪微博
        ShareSDK.connectSinaWeiboWithAppKey("4071914616", appSecret: "273f52407df87a15cbe06840c64cc0d2", redirectUri: "http://www.weibo.com/balancea")
        //豆瓣
ShareSDK.connectDoubanWithAppKey("02e0393e2cfbecb508a0abba86f3c61f", appSecret: "9a000e648fd0cbce", redirectUri: "http://www.ijilu.com")
        //QQ空间
        ShareSDK.connectQZoneWithAppKey("1103527931", appSecret:"WEKkOPW0NJkc1cwS", qqApiInterfaceCls: QQApiInterface.classForCoder(), tencentOAuthCls: TencentOAuth.classForCoder())
        //QQ
        ShareSDK.connectQQWithAppId("1103527931", qqApiCls:QQApiInterface.classForCoder())
       //链接微信
        ShareSDK.connectWeChatWithAppId("wx5f09f3b56fd1faf7", wechatCls: WXApi.classForCoder())
        //微信好友
      ShareSDK.connectWeChatSessionWithAppId("wx5f09f3b56fd1faf7", wechatCls:WXApi.classForCoder())
       //微信朋友圈
    ShareSDK.connectWeChatTimelineWithAppId("wx5f09f3b56fd1faf7", wechatCls: WXApi.classForCoder())
        ShareSDK.connectRenRenWithAppKey("3899f3ffa97544a3a6767ce3d7530142", appSecret: "4a9df27a701742c09d05dbb52ef1483a")
```

9、在分享按钮或其他控件的动作中添加实现代码:
```
func share() {
        var publishContent : ISSContent = ShareSDK.content("分享文字", defaultContent:"默认分享内容,没内容时显示",image:nil, title:"提示",url:"返回链接",description:"这是一条测试信息",mediaType:SSPublishContentMediaTypeNews)
        ShareSDK.showShareActionSheet(nil, shareList: nil, content: publishContent, statusBarTips: true, authOptions: nil, shareOptions: nil, result: {(type:ShareType,state:SSResponseState,statusInfo:ISSPlatformShareInfo!,error:ICMErrorInfo!,end:Bool) in
            println(state.value)
            if (state.value == SSResponseStateSuccess.value){
                println("分享成功")
                var alert = UIAlertView(title: "提示", message:"分享成功", delegate:self, cancelButtonTitle: "ok")
                alert.show()
            }
            else {if (state.value == 2) {
                var alert = UIAlertView(title: "提示", message:"您没有安装客户端,无法使用分享功能!", delegate:self, cancelButtonTitle: "ok")
                alert.show()
                println(error.errorCode())
                println(error.errorDescription())
                println()
                }
            }
        })
    }
```
至此,已可以使用新浪微博网页授权进行分享,如需使用客户端,只需添加SSO授权即可。
10、配置新浪微博SSO(免帐号登录)
登录新浪微博的开放平台,获取AppID 。新浪微博的url scheme的设置格式为wb+AppID



![添加新浪微博的AppID.jpg](http:https://img.haomeiwen.com/i151218/fc37c42592c8779d.jpg)

这样一个通过第三方ShareSDK的案例就结束了。

具体可参考ShareSDK-OC文档:

http://wiki.mob.com/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97/


#####打赏专用:
http://weibo.com/p/1001603800398153516379

上一篇下一篇

猜你喜欢

热点阅读