一、sharesdk是一个做第三方分享的框架,这个框架可以分享到主流的第三方平台上面
二、sharesdk的集成:
首先明白总共需要做的几件事情:1.下载sharesdk并且集成sharesdk这个第三方框架,并且导入文档中所需要对应的类,重新运行一下之后没有报错在进行下一步,2.去sharesdk的官网和各种你需要分享的平台上面去申请相对应的appID和appkey来操作,3.添加URLTypes,4.去适配ios9的系统,因为这个现在主流的app都是需要适配的,并且有的平台还需要去审核app的,不然只能使开发者账号能分享成功
1、sharesdk官方集成文档这个只需要根据集成文档一步步去集成,添加所需要的文件就可以了
2、申请sharesdkAppkey的网址,和其他各种平台申请的网址根据这个上面的appkey的申请规则去一步步的申请相对应的appkey
3、在工程中去添加URLTypes如图所示:
这总共分成两部分,一个是sharesdk的URL Types,一个是添加各种平台下的URL Types
4、用来适配iOS9的系统, 适配iOS9地址基本上这个也是必须要配置的,因为iOS9都是需要适配的,其中白名单比较重要!
5、其中whatsapp和FacebookMessage是不需要通过app审核的,但是却是需要安装客户端的,不安装客户端是无法进行分享的。
6、在appdelegate中的操作:
//==========ShareSDK头文件====================
#import
#import
//以下是ShareSDK必须添加的依赖库:
//1、libicucore.dylib
//2、libz.dylib
//3、libstdc++.dylib
//4、JavaScriptCore.framework
//==========以下是各个平台SDK的头文件,根据需要继承的平台添加===
//腾讯开放平台(对应QQ和QQ空间)SDK头文件
#import
#import
//以下是腾讯SDK的依赖库:
//libsqlite3.dylib
//微信SDK头文件
#import "WXApi.h"
//以下是微信SDK的依赖库:
//libsqlite3.dylib
//新浪微博SDK头文件
#import "WeiboSDK.h"
//新浪微博SDK需要在项目Build Settings中的Other Linker Flags添加"-ObjC"
//以下是新浪微博SDK的依赖库:
//ImageIO.framework
//libsqlite3.dylib
//AdSupport.framework
//人人SDK头文件
#import
//Kakao SDK头文件
#import
//支付宝SDK
#import "APOpenAPI.h"
//易信SDK头文件
#import "YXApi.h"
//Facebook Messenger SDK
#import
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[ShareSDK registerApp:@"14157c6e15860"
activePlatforms:@[
@(SSDKPlatformTypeSinaWeibo),
@(SSDKPlatformTypeTencentWeibo),
@(SSDKPlatformTypeMail),
@(SSDKPlatformTypeSMS),
@(SSDKPlatformTypeCopy),
@(SSDKPlatformTypeFacebook),
@(SSDKPlatformTypeTwitter),
@(SSDKPlatformTypeWechat),
@(SSDKPlatformTypeQQ),
@(SSDKPlatformTypeDouBan),
@(SSDKPlatformTypeRenren),
@(SSDKPlatformTypeKaixin),
@(SSDKPlatformTypeGooglePlus),
@(SSDKPlatformTypePocket),
@(SSDKPlatformTypeInstagram),
@(SSDKPlatformTypeLinkedIn),
@(SSDKPlatformTypeTumblr),
@(SSDKPlatformTypeFlickr),
@(SSDKPlatformTypeWhatsApp),
@(SSDKPlatformTypeYouDaoNote),
@(SSDKPlatformTypeLine),
@(SSDKPlatformTypeYinXiang),
@(SSDKPlatformTypeEvernote),
@(SSDKPlatformTypeYinXiang),
@(SSDKPlatformTypeAliPaySocial),
@(SSDKPlatformTypePinterest),
@(SSDKPlatformTypeKakao),
@(SSDKPlatformSubTypeKakaoTalk),
@(SSDKPlatformSubTypeKakaoStory),
@(SSDKPlatformTypeDropbox),
@(SSDKPlatformTypeVKontakte),
@(SSDKPlatformTypeMingDao),
@(SSDKPlatformTypePrint),
@(SSDKPlatformTypeYiXin),
@(SSDKPlatformTypeInstapaper),
@(SSDKPlatformTypeFacebookMessenger)
]
onImport:^(SSDKPlatformType platformType) {
// switch (platformType)
// {
// case SSDKPlatformTypeWechat:
// [ShareSDKConnector connectWeChat:[WXApi class] delegate:self];
// break;
// case SSDKPlatformTypeQQ:
// [ShareSDKConnector connectQQ:[QQApiInterface class]
// tencentOAuthClass:[TencentOAuth class]];
// break;
// case SSDKPlatformTypeSinaWeibo:
// [ShareSDKConnector connectWeibo:[WeiboSDK class]];
// break;
// case SSDKPlatformTypeRenren:
// [ShareSDKConnector connectRenren:[RennClient class]];
// break;
// case SSDKPlatformTypeKakao:
// [ShareSDKConnector connectKaKao:[KOSession class]];
// break;
// case SSDKPlatformTypeAliPaySocial:
// [ShareSDKConnector connectAliPaySocial:[APOpenAPI class]];
// break;
// case SSDKPlatformTypeYiXin:
// [ShareSDKConnector connectYiXin:[YXApi class]];
// break;
// case SSDKPlatformTypeFacebookMessenger:
// [ShareSDKConnector connectFacebookMessenger:[FBSDKMessengerSharer class]];
// break;
// default:
// break;
// }
}
onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) {
switch (platformType)
{
case SSDKPlatformTypeSinaWeibo:
//设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
[appInfo SSDKSetupSinaWeiboByAppKey:@"568898243"
appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
redirectUri:@"http://www.sharesdk.cn"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeTencentWeibo:
//设置腾讯微博应用信息,其中authType设置为只用Web形式授权
[appInfo SSDKSetupTencentWeiboByAppKey:@"801307650"
appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
redirectUri:@"http://www.sharesdk.cn"];
break;
case SSDKPlatformTypeFacebook:
//设置Facebook应用信息,其中authType设置为只用SSO形式授权
[appInfo SSDKSetupFacebookByApiKey:@"250721551966410"
appSecret:@"4fe025c2e27f8983afbba9281b5a14d8"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeTwitter:
[appInfo SSDKSetupTwitterByConsumerKey:@"LRBM0H75rWrU9gNHvlEAA2aOy"
consumerSecret:@"gbeWsZvA9ELJSdoBzJ5oLKX0TU09UOwrzdGfo9Tg7DjyGuMe8G"
redirectUri:@"http://mob.com"];
break;
case SSDKPlatformTypeWechat:
[appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"
appSecret:@"64020361b8ec4c99936c0e3999a9f249"];
break;
case SSDKPlatformTypeQQ:
[appInfo SSDKSetupQQByAppId:@"100371282"
appKey:@"aed9b0303e3ed1e27bae87c33761161d"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeDouBan:
[appInfo SSDKSetupDouBanByApiKey:@"02e2cbe5ca06de5908a863b15e149b0b"
secret:@"9f1e7b4f71304f2f"
redirectUri:@"http://www.sharesdk.cn"];
break;
case SSDKPlatformTypeRenren:
[appInfo SSDKSetupRenRenByAppId:@"226427"
appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
secretKey:@"f29df781abdd4f49beca5a2194676ca4"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeKaixin:
[appInfo SSDKSetupKaiXinByApiKey:@"358443394194887cee81ff5890870c7c"
secretKey:@"da32179d859c016169f66d90b6db2a23"
redirectUri:@"http://www.sharesdk.cn/"];
break;
case SSDKPlatformTypeGooglePlus:
[appInfo SSDKSetupGooglePlusByClientID:@"232554794995.apps.googleusercontent.com"
clientSecret:@"PEdFgtrMw97aCvf0joQj7EMk"
redirectUri:@"http://localhost"];
break;
case SSDKPlatformTypePocket:
[appInfo SSDKSetupPocketByConsumerKey:@"11496-de7c8c5eb25b2c9fcdc2b627"
redirectUri:@"pocketapp1234"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeInstagram:
[appInfo SSDKSetupInstagramByClientID:@"ff68e3216b4f4f989121aa1c2962d058"
clientSecret:@"1b2e82f110264869b3505c3fe34e31a1"
redirectUri:@"http://sharesdk.cn"];
break;
case SSDKPlatformTypeLinkedIn:
[appInfo SSDKSetupLinkedInByApiKey:@"ejo5ibkye3vo"
secretKey:@"cC7B2jpxITqPLZ5M"
redirectUrl:@"http://sharesdk.cn"];
break;
case SSDKPlatformTypeTumblr:
[appInfo SSDKSetupTumblrByConsumerKey:@"2QUXqO9fcgGdtGG1FcvML6ZunIQzAEL8xY6hIaxdJnDti2DYwM"
consumerSecret:@"3Rt0sPFj7u2g39mEVB3IBpOzKnM3JnTtxX2bao2JKk4VV1gtNo"
callbackUrl:@"http://sharesdk.cn"];
break;
case SSDKPlatformTypeFlickr:
[appInfo SSDKSetupFlickrByApiKey:@"33d833ee6b6fca49943363282dd313dd"
apiSecret:@"3a2c5b42a8fbb8bb"];
break;
case SSDKPlatformTypeYouDaoNote:
[appInfo SSDKSetupYouDaoNoteByConsumerKey:@"dcde25dca105bcc36884ed4534dab940"
consumerSecret:@"d98217b4020e7f1874263795f44838fe"
oauthCallback:@"http://www.sharesdk.cn/"];
break;
//印象笔记分为国内版和国际版,注意区分平台
//设置印象笔记(中国版)应用信息
case SSDKPlatformTypeYinXiang:
//设置印象笔记(国际版)应用信息
case SSDKPlatformTypeEvernote:
[appInfo SSDKSetupEvernoteByConsumerKey:@"sharesdk-7807"
consumerSecret:@"d05bf86993836004"
sandbox:YES];
break;
case SSDKPlatformTypeKakao:
[appInfo SSDKSetupKaKaoByAppKey:@"48d3f524e4a636b08d81b3ceb50f1003"
restApiKey:@"ac360fa50b5002637590d24108e6cb10"
redirectUri:@"http://www.mob.com/oauth"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeAliPaySocial:
[appInfo SSDKSetupAliPaySocialByAppId:@"2015072400185895"];
break;
case SSDKPlatformTypePinterest:
[appInfo SSDKSetupPinterestByClientId:@"4797078908495202393"];
break;
case SSDKPlatformTypeDropbox:
[appInfo SSDKSetupDropboxByAppKey:@"i5vw2mex1zcgjcj"
appSecret:@"3i9xifsgb4omr0s"
oauthCallback:@"https://www.sharesdk.cn"];
break;
case SSDKPlatformTypeVKontakte:
[appInfo SSDKSetupVKontakteByApplicationId:@"5312801"
secretKey:@"ZHG2wGymmNUCRLG2r6CY"];
break;
case SSDKPlatformTypeMingDao:
[appInfo SSDKSetupMingDaoByAppKey:@"EEEE9578D1D431D3215D8C21BF5357E3"
appSecret:@"5EDE59F37B3EFA8F65EEFB9976A4E933"
redirectUri:@"http://sharesdk.cn"];
break;
case SSDKPlatformTypeYiXin:
[appInfo SSDKSetupYiXinByAppId:@"yx0d9a9f9088ea44d78680f3274da1765f"
appSecret:@"1a5bd421ae089c3"
redirectUri:@"https://open.yixin.im/resource/oauth2_callback.html"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeInstapaper:
[appInfo SSDKSetupInstapaperByConsumerKey:@"4rDJORmcOcSAZL1YpqGHRI605xUvrLbOhkJ07yO0wWrYrc61FA"
consumerSecret:@"GNr1GespOQbrm8nvd7rlUsyRQsIo3boIbMguAl9gfpdL0aKZWe"];
break;
default:
break;
}
}];
return YES;
}
其中Facebookmessage需要添加连接的头文件,和判断是否安装客户端都是需要导入头文件的
#import
#import
#import
#import
#import
//直接分享的
//1、创建分享参数
NSArray* imageArray = @[@"http://www.mob.com/images/logo_black.png",[UIImage imageNamed:@"shareImg.png"]];
if (imageArray) {
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:@"分享内容 http://baidu.com"
images:imageArray
url:[NSURL URLWithString:@"http://www.baidu.com"]
title:@"分享标题"
type:SSDKContentTypeAuto];
//2、直接分享
[ShareSDK share:SSDKPlatformTypeFacebook parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
switch (state) {
case SSDKResponseStateSuccess:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享成功"
message:nil
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
break;
}
case SSDKResponseStateFail:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
break;
}
case SSDKResponseStateCancel:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享取消"
message:nil
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
}
default:
break;
}
}];
if (![ShareSDK isClientInstalled:SSDKPlatformTypeWhatsApp]) {
//判断是否安装了客户端
[self showAlterViewWithTitle:@"分享失败" WithMessage:@"未安装客户端" withCancelBtn:@"OK"];
}else{
[self showAlterViewWithTitle:@"分享失败" WithMessage:[NSString stringWithFormat:@"%@",error] withCancelBtn:@"OK"];
}
其中FacebookMessage是不能够分享文字内容的,文字内容只能够让用户自己去书写,其他平台是无法传入的,并且也是可以设置各种平台下分享不同的内容,不同的平台下面,sharesdk都定义了一个不同的分享的方法。
三、添加下微信分享的流程
1.按照上面的流程去集成sharesdk,使其编译不出问题
2.去微信的开发者中心的平台去申请APPID和APPSecret,
3.还是跟上面一个直接写代码,添加文件!然后去直接设置分享参数,直接分享。
4.去添加白名单,就是去在工程中去添加URLTypes,在上图中也可以看到
5,最后去适配iOS9的系统