ShareSDK的使用---实现三方登陆及分享
来源:互联网 发布:河南网络知识竞赛 编辑:程序博客网 时间:2024/05/21 18:22
使用的shareSDK,所以需要先到shareSdk官网注册一个开发者账号,免费的。http://mob.com/。然后新建一个应用程序,获取appID。
1.必须添加的依赖库如下:
SystemConfiguration.framework ,
QuartzCore.framework ,
CoreTelephony.framework ,
libicucore.dylib ,
libz.1.2.5.dylib ,
Security.framework
以下依赖库可根据您支持的社交平台情况进行添加
MessageUI.framework 支持短信和邮件分享必备库
libstdc++.dylib QQ好友和QQ空间SSO必备库,如不需要SSO授权可不添加。(最新注册QQ互联开发者帐号只支持SSO授权,只是老开发者才可以使用网页授权)
libsqlite3.dylib QQ好友和QQ空间SSO必备库,如不需要SSO授权可不添加。(最新注册QQ互联开发者帐号只支持SSO授权,只是老开发者才可以使用网页授权)
CoreMotion.framework 如果不使用Google+可以不加
CoreLocation.framework如果不使用Google+可以不加
MediaPlayer.framework 如果不使用Google+可以不加
CoreText.framework如果不使用Google+可以不加
AssetsLibrary.framework 如果不使用Google+可以不加
AddressBook.framework如果不使用Google+可以不加
Social.framework 腾讯微博SDK依赖库
Accounts.framework 腾讯微博SDK依赖库
2.设置appId
打开*AppDelegate.m(*代表你的工程名字)和你想要添加分享的vc分别导入文件头ShareSDK.h
#import <ShareSDK/ShareSDK.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "WXApi.h"
#import "WeiboApi.h"
#import "WeiboSDK.h"
#import <RennSDK/RennSDK.h>
在- (BOOL)application: didFinishLaunchingWithOptions:方法中调用registerApp方法来初始化SDK并且初始化第三方平台
[self getShareSdkStart];
-(void) getShareSdkStart
{
[ShareSDK registerApp:@"api20"];//字符串api20为您的ShareSDK的AppKey
//添加新浪微博应用 注册网址http://open.weibo.com
[ShareSDK connectSinaWeiboWithAppKey:@"568898243"
appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
redirectUri:@"http://www.sharesdk.cn"];
//当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台
[ShareSDK connectSinaWeiboWithAppKey:@"568898243"
appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
redirectUri:@"http://www.sharesdk.cn"
weiboSDKCls:[WeiboSDK class];
//添加腾讯微博应用 注册网址http://dev.t.qq.com
[ShareSDK connectTencentWeiboWithAppKey:@"801307650"
appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
redirectUri:@"http://www.sharesdk.cn"
wbApiCls:[WeiboApi class];
//添加QQ空间应用 注册网址http://connect.qq.com/intro/login/
[ShareSDK connectQZoneWithAppKey:@"100371282"
appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
qqApiInterfaceCls:[QQApiInterface class]
tencentOAuthCls:[TencentOAuth class];
//添加QQ应用 注册网址http://open.qq.com/
[ShareSDK connectQQWithQZoneAppKey:@"100371282"
qqApiInterfaceCls:[QQApiInterface class]
tencentOAuthCls:[TencentOAuth class];
//添加微信应用 注册网址http://open.weixin.qq.com
[ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
wechatCls:[WXApi class];
//添加搜狐微博应用 注册网址http://open.t.sohu.com
[ShareSDK connectSohuWeiboWithConsumerKey:@"SAfmTG1blxZY3HztESWx"
consumerSecret:@"yfTZf)!rVwh*3dqQuVJVsUL37!F)!yS9S!Orcsij"
redirectUri:@"http://www.sharesdk.cn"];
//添加豆瓣应用 注册网址http://developers.douban.com
[ShareSDK connectDoubanWithAppKey:@"07d08fbfc1210e931771af3f43632bb9"
appSecret:@"e32896161e72be91"
redirectUri:@"http://dev.kumoway.com/braininference/infos.php"];
//添加人人网应用 注册网址http://dev.renren.com
[ShareSDK connectRenRenWithAppId:@"226427"
appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
appSecret:@"f29df781abdd4f49beca5a2194676ca4"
renrenClientClass:[RennClient class];
//添加开心网应用 注册网址http://open.kaixin001.com
[ShareSDK connectKaiXinWithAppKey:@"358443394194887cee81ff5890870c7c"
appSecret:@"da32179d859c016169f66d90b6db2a23"
redirectUri:@"http://www.sharesdk.cn/"];
//添加Instapaper应用 注册网址http://www.instapaper.com/main/request_oauth_consumer_token
[ShareSDK connectInstapaperWithAppKey:@"4rDJORmcOcSAZL1YpqGHRI605xUvrLbOhkJ07yO0wWrYrc61FA"
appSecret:@"GNr1GespOQbrm8nvd7rlUsyRQsIo3boIbMguAl9gfpdL0aKZWe"];
//添加有道云笔记应用 注册网址http://note.youdao.com/open/developguide.html#app
[ShareSDK connectYouDaoNoteWithConsumerKey:@"dcde25dca105bcc36884ed4534dab940"
consumerSecret:@"d98217b4020e7f1874263795f44838fe"
redirectUri:@"http://www.sharesdk.cn/"];
//添加Facebook应用 注册网址https://developers.facebook.com
[ShareSDK connectFacebookWithAppKey:@"107704292745179"
appSecret:@"38053202e1a5fe26c80c753071f0b573"];
//添加Twitter应用 注册网址https://dev.twitter.com
[ShareSDK connectTwitterWithConsumerKey:@"mnTGqtXk0TYMXYTN7qUxg"
consumerSecret:@"ROkFqr8c3m1HXqS3rm3TJ0WkAJuwBOSaWhPbZ9Ojuc"
redirectUri:@"http://www.sharesdk.cn"];
//连接邮件
[ShareSDK connectMail];
}
3.添加实现代码
打开需要集成分享功能的视图源码,把如下代码复制并粘贴到你将弹出一个分享列表的位置,例如到响应分享按钮的方法中。并且修改相应的参数即可。
在viewDidLoad里面初始化rightbutton
UIButton*rightButton = [UIButton alloc]initWithFrame:CGRectMake(0,0,57,45)];
rightButton.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
[rightButton setImage:[UIImage imageNamed:@"share1.png"]forState:UIControlStateNormal];
rightButton.tintColor = [UIColor redColor];
[rightButton addTarget:self action:@selector(selectRightAction:)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightItem = [UIBarButtonItem alloc]initWithCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightItem;
点击方法
- (void)selectRightAction:(UIButton *)sender
{
//创建分享内容
NSString *imagePath = [NSBundle mainBundle] pathForResource:@"1-1" ofType:@"jpg"];
//构造分享内容
id<ISSContent> publishContent = [ShareSDK content:@"分享内容"
defaultContent:@"测试一下"
image:[ShareSDK imageWithPath:imagePath]
title:@"ShareSDK"
url:@"http://www.mob.com"
description:@"这是一条测试信息"
mediaType:SSPublishContentMediaTypeNews];
//创建弹出菜单容器
id<ISSContainer> container = [ShareSDK container];
[container setIPadContainerWithView:sender arrowDirect:UIPopoverArrowDirectionUp];
// 选择要添加的功能
NSArray *shareList = [ShareSDK customShareListWithType:
SHARE_TYPE_NUMBER(ShareTypeSinaWeibo),
SHARE_TYPE_NUMBER(ShareTypeQQSpace),
SHARE_TYPE_NUMBER(ShareTypeTwitter),
SHARE_TYPE_NUMBER(ShareTypeRenren),
SHARE_TYPE_NUMBER(ShareTypeMail),
SHARE_TYPE_NUMBER(ShareTypeWeixiTimeline),
SHARE_TYPE_NUMBER(ShareTypeYouDaoNote),
SHARE_TYPE_NUMBER(ShareTypeTencentWeibo),
nil];
//弹出分享菜单
[ShareSDK showShareActionSheet:container
shareList:shareList
content:publishContent
statusBarTips:YES
authOptions:nil
shareOptions:nil
result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
if (state == SSResponseStateSuccess)
{
NSLog(NSLocalizedString(@"TEXT_ShARE_SUC", @"分享成功"));
}
else if (state == SSResponseStateFail)
{
NSLog(NSLocalizedString(@"TEXT_ShARE_FAI", @"分享失败,错误码:%d,错误描述:%@"), [error errorCode], [error errorDescription]);
}
}];
}
4.支持微信
在微信开放平台(http://open.weixin.qq.com/ )注册应用并取得应用的AppID,然后打开下图位置,在URL Types中添加微信AppID

1
#检查是否已加入handleOpenURL的处理方法,如果没有则添加如下代码:
import “WXApi.h“
- (BOOL)application:(UIApplication *)application
handleOpenURL:(NSURL *)url
{
return [ShareSDK handleOpenURL:url
wxDelegate:self];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [ShareSDK handleOpenURL:url
sourceApplication:sourceApplication
annotation:annotation
wxDelegate:self];
}
打开*AppDelegate.m(*代表你的工程名字)文件,在- application: didFinishLaunchingWithOptions: 方法内添加如下语句:
[ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885" //微信APPID
appSecret:@"64020361b8ec4c99936c0e3999a9f249" //微信APPSecret
wechatCls:[WXApi class];
1.必须添加的依赖库如下:
SystemConfiguration.framework ,
QuartzCore.framework ,
CoreTelephony.framework ,
libicucore.dylib ,
libz.1.2.5.dylib ,
Security.framework
以下依赖库可根据您支持的社交平台情况进行添加
MessageUI.framework 支持短信和邮件分享必备库
libstdc++.dylib QQ好友和QQ空间SSO必备库,如不需要SSO授权可不添加。(最新注册QQ互联开发者帐号只支持SSO授权,只是老开发者才可以使用网页授权)
libsqlite3.dylib QQ好友和QQ空间SSO必备库,如不需要SSO授权可不添加。(最新注册QQ互联开发者帐号只支持SSO授权,只是老开发者才可以使用网页授权)
CoreMotion.framework 如果不使用Google+可以不加
CoreLocation.framework如果不使用Google+可以不加
MediaPlayer.framework 如果不使用Google+可以不加
CoreText.framework如果不使用Google+可以不加
AssetsLibrary.framework 如果不使用Google+可以不加
AddressBook.framework如果不使用Google+可以不加
Social.framework 腾讯微博SDK依赖库
Accounts.framework 腾讯微博SDK依赖库
2.设置appId
打开*AppDelegate.m(*代表你的工程名字)和你想要添加分享的vc分别导入文件头ShareSDK.h
#import <ShareSDK/ShareSDK.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "WXApi.h"
#import "WeiboApi.h"
#import "WeiboSDK.h"
#import <RennSDK/RennSDK.h>
在- (BOOL)application: didFinishLaunchingWithOptions:方法中调用registerApp方法来初始化SDK并且初始化第三方平台
[self getShareSdkStart];
-(void) getShareSdkStart
{
[ShareSDK registerApp:@"api20"];//字符串api20为您的ShareSDK的AppKey
//添加新浪微博应用 注册网址http://open.weibo.com
[ShareSDK connectSinaWeiboWithAppKey:@"568898243"
appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
redirectUri:@"http://www.sharesdk.cn"];
//当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台
[ShareSDK connectSinaWeiboWithAppKey:@"568898243"
appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
redirectUri:@"http://www.sharesdk.cn"
weiboSDKCls:[WeiboSDK class];
//添加腾讯微博应用 注册网址http://dev.t.qq.com
[ShareSDK connectTencentWeiboWithAppKey:@"801307650"
appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
redirectUri:@"http://www.sharesdk.cn"
wbApiCls:[WeiboApi class];
//添加QQ空间应用 注册网址http://connect.qq.com/intro/login/
[ShareSDK connectQZoneWithAppKey:@"100371282"
appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
qqApiInterfaceCls:[QQApiInterface class]
tencentOAuthCls:[TencentOAuth class];
//添加QQ应用 注册网址http://open.qq.com/
[ShareSDK connectQQWithQZoneAppKey:@"100371282"
qqApiInterfaceCls:[QQApiInterface class]
tencentOAuthCls:[TencentOAuth class];
//添加微信应用 注册网址http://open.weixin.qq.com
[ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
wechatCls:[WXApi class];
//添加搜狐微博应用 注册网址http://open.t.sohu.com
[ShareSDK connectSohuWeiboWithConsumerKey:@"SAfmTG1blxZY3HztESWx"
consumerSecret:@"yfTZf)!rVwh*3dqQuVJVsUL37!F)!yS9S!Orcsij"
redirectUri:@"http://www.sharesdk.cn"];
//添加豆瓣应用 注册网址http://developers.douban.com
[ShareSDK connectDoubanWithAppKey:@"07d08fbfc1210e931771af3f43632bb9"
appSecret:@"e32896161e72be91"
redirectUri:@"http://dev.kumoway.com/braininference/infos.php"];
//添加人人网应用 注册网址http://dev.renren.com
[ShareSDK connectRenRenWithAppId:@"226427"
appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
appSecret:@"f29df781abdd4f49beca5a2194676ca4"
renrenClientClass:[RennClient class];
//添加开心网应用 注册网址http://open.kaixin001.com
[ShareSDK connectKaiXinWithAppKey:@"358443394194887cee81ff5890870c7c"
appSecret:@"da32179d859c016169f66d90b6db2a23"
redirectUri:@"http://www.sharesdk.cn/"];
//添加Instapaper应用 注册网址http://www.instapaper.com/main/request_oauth_consumer_token
[ShareSDK connectInstapaperWithAppKey:@"4rDJORmcOcSAZL1YpqGHRI605xUvrLbOhkJ07yO0wWrYrc61FA"
appSecret:@"GNr1GespOQbrm8nvd7rlUsyRQsIo3boIbMguAl9gfpdL0aKZWe"];
//添加有道云笔记应用 注册网址http://note.youdao.com/open/developguide.html#app
[ShareSDK connectYouDaoNoteWithConsumerKey:@"dcde25dca105bcc36884ed4534dab940"
consumerSecret:@"d98217b4020e7f1874263795f44838fe"
redirectUri:@"http://www.sharesdk.cn/"];
//添加Facebook应用 注册网址https://developers.facebook.com
[ShareSDK connectFacebookWithAppKey:@"107704292745179"
appSecret:@"38053202e1a5fe26c80c753071f0b573"];
//添加Twitter应用 注册网址https://dev.twitter.com
[ShareSDK connectTwitterWithConsumerKey:@"mnTGqtXk0TYMXYTN7qUxg"
consumerSecret:@"ROkFqr8c3m1HXqS3rm3TJ0WkAJuwBOSaWhPbZ9Ojuc"
redirectUri:@"http://www.sharesdk.cn"];
//连接邮件
[ShareSDK connectMail];
}
3.添加实现代码
打开需要集成分享功能的视图源码,把如下代码复制并粘贴到你将弹出一个分享列表的位置,例如到响应分享按钮的方法中。并且修改相应的参数即可。
在viewDidLoad里面初始化rightbutton
UIButton*rightButton = [UIButton alloc]initWithFrame:CGRectMake(0,0,57,45)];
rightButton.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
[rightButton setImage:[UIImage imageNamed:@"share1.png"]forState:UIControlStateNormal];
rightButton.tintColor = [UIColor redColor];
[rightButton addTarget:self action:@selector(selectRightAction:)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightItem = [UIBarButtonItem alloc]initWithCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightItem;
点击方法
- (void)selectRightAction:(UIButton *)sender
{
//创建分享内容
NSString *imagePath = [NSBundle mainBundle] pathForResource:@"1-1" ofType:@"jpg"];
//构造分享内容
id<ISSContent> publishContent = [ShareSDK content:@"分享内容"
defaultContent:@"测试一下"
image:[ShareSDK imageWithPath:imagePath]
title:@"ShareSDK"
url:@"http://www.mob.com"
description:@"这是一条测试信息"
mediaType:SSPublishContentMediaTypeNews];
//创建弹出菜单容器
id<ISSContainer> container = [ShareSDK container];
[container setIPadContainerWithView:sender arrowDirect:UIPopoverArrowDirectionUp];
// 选择要添加的功能
NSArray *shareList = [ShareSDK customShareListWithType:
SHARE_TYPE_NUMBER(ShareTypeSinaWeibo),
SHARE_TYPE_NUMBER(ShareTypeQQSpace),
SHARE_TYPE_NUMBER(ShareTypeTwitter),
SHARE_TYPE_NUMBER(ShareTypeRenren),
SHARE_TYPE_NUMBER(ShareTypeMail),
SHARE_TYPE_NUMBER(ShareTypeWeixiTimeline),
SHARE_TYPE_NUMBER(ShareTypeYouDaoNote),
SHARE_TYPE_NUMBER(ShareTypeTencentWeibo),
nil];
//弹出分享菜单
[ShareSDK showShareActionSheet:container
shareList:shareList
content:publishContent
statusBarTips:YES
authOptions:nil
shareOptions:nil
result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
if (state == SSResponseStateSuccess)
{
NSLog(NSLocalizedString(@"TEXT_ShARE_SUC", @"分享成功"));
}
else if (state == SSResponseStateFail)
{
NSLog(NSLocalizedString(@"TEXT_ShARE_FAI", @"分享失败,错误码:%d,错误描述:%@"), [error errorCode], [error errorDescription]);
}
}];
}
4.支持微信
在微信开放平台(http://open.weixin.qq.com/ )注册应用并取得应用的AppID,然后打开下图位置,在URL Types中添加微信AppID

1
#检查是否已加入handleOpenURL的处理方法,如果没有则添加如下代码:
import “WXApi.h“
- (BOOL)application:(UIApplication *)application
handleOpenURL:(NSURL *)url
{
return [ShareSDK handleOpenURL:url
wxDelegate:self];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [ShareSDK handleOpenURL:url
sourceApplication:sourceApplication
annotation:annotation
wxDelegate:self];
}
打开*AppDelegate.m(*代表你的工程名字)文件,在- application: didFinishLaunchingWithOptions: 方法内添加如下语句:
[ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885" //微信APPID
appSecret:@"64020361b8ec4c99936c0e3999a9f249" //微信APPSecret
wechatCls:[WXApi class];
0 0
- ShareSDK的使用---实现三方登陆及分享
- sharesdk 实现三方登陆、分享及关注的功能
- iOS 项目 ShareSDK 实现三方登陆 分享
- 使用ShareSDK三方登陆
- 通过使用第三方SDK来实现应用的分享,第三方登陆,数据信息统计等功能(ShareSDK)。
- ios ShareSDK 分享、登陆功能的实现
- shareSDK使用小总结(分享+第三方授权登陆)
- 使用ShareSDK实现第三方分享和第三方登陆 以及短信验证码的功能 配置的中的一些坑
- iOS shareSDK的分享与第三方登陆 (详解)
- ShareSDK实现第三方登陆
- Android集成ShareSDK分享及三方登录功能
- 第三方SDK:ShareSDK 快捷分享 + 登陆
- 用shareSDK实现ios应用第三方登陆和分享到第三方功能(一)
- Android集成ShareSDK的分享及第三方登录
- 6.8.1 使用ShareSDK 实现第三方分享,登录 微博,
- 使用ShareSDK做第三方登陆功能,http无法连接和qq空间分享没有出现的解决方法
- 使用友盟来实现第三方的分享,登陆
- 【第三方SDK】使用ShareSDK实现新浪微博的一键分享功能
- IE6中网页不显示iframe不显示问题
- Android开源项目分类汇总
- 实现对UIAlertController和UIAlertView判断系统后的简单封装
- 常用sql语句
- I2C和SPI总线对比
- ShareSDK的使用---实现三方登陆及分享
- 你为什么会离开游戏行业
- 树莓派硬件到,可以开搞了
- 【android】多个avtivity之间startActivityForResult小解
- mysql in 内排序
- MFC中ON_UPDATE_COMMAND_UI和ON_COMMAND消息区别
- Android开发-自定义view-简化版自定义开关
- 马云写给儿子的一封信,感动无数人
- android studio下多渠道打包