用ShareSDK 进行第三方分享

1.首先要先注册自己的appkey在shareSDK官网里面
2.下载shareSDK 文档,可以根据需要下载自己需要的
如图

3.将下载好的shareSDK 解压后加入工程里面

4.添加依赖库

//必须添加的库
必须添加的依赖库如下(Xcode 7 下 .dylib库后缀名更改为.tbd):
libicucore.dylib
libz.dylib
libstdc++.dylib
JavaScriptCore.framework

新浪微博SDK依赖库
ImageIO.framework
libsqlite3.dylib

QQ好友和QQ空间SDK依赖库
libsqlite3.dylib

微信SDK依赖库
libsqlite3.dylib

短信和邮件需要依赖库
MessageUI.framework

5.打开*AppDelegate.m
导入需要的头文件 如图

6.在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions里面添加代码

  • (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
    {
    /
    • 设置ShareSDK的appKey,如果尚未在ShareSDK官网注册过App,请移步到http://mob.com/login 登录后台进行应用注册

    • 在将生成的AppKey传入到此方法中。

    • 方法中的第二个第三个参数为需要连接社交平台SDK时触发,

    • 在此事件中写入连接代码。第四个参数则为配置本地社交平台时触发,根据返回的平台类型来配置平台信息。

    • 如果您使用的时服务端托管平台信息时,第二、四项参数可以传入nil,第三项参数则根据服务端托管平台来决定要连接的社交SDK。
      */
      [ShareSDK registerApp:@"iosv1101"

      activePlatforms:@[
      @(SSDKPlatformTypeSinaWeibo),
      @(SSDKPlatformTypeMail),
      @(SSDKPlatformTypeSMS),
      @(SSDKPlatformTypeCopy),
      @(SSDKPlatformTypeWechat),
      @(SSDKPlatformTypeQQ),
      @(SSDKPlatformTypeRenren),
      @(SSDKPlatformTypeGooglePlus)]
      onImport:^(SSDKPlatformType platformType)
      {
      switch (platformType)
      {
      case SSDKPlatformTypeWechat:
      [ShareSDKConnector connectWeChat:[WXApi class]];
      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;
      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 SSDKPlatformTypeWechat:
      [appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"
      appSecret:@"64020361b8ec4c99936c0e3999a9f249"];
      break;
      case SSDKPlatformTypeQQ:
      [appInfo SSDKSetupQQByAppId:@"100371282"
      appKey:@"aed9b0303e3ed1e27bae87c33761161d"
      authType:SSDKAuthTypeBoth];
      break;
      case SSDKPlatformTypeRenren:
      [appInfo SSDKSetupRenRenByAppId:@"226427"
      appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
      secretKey:@"f29df781abdd4f49beca5a2194676ca4"
      authType:SSDKAuthTypeBoth];
      break;
      case SSDKPlatformTypeGooglePlus:
      [appInfo SSDKSetupGooglePlusByClientID:@"232554794995.apps.googleusercontent.com"
      clientSecret:@"PEdFgtrMw97aCvf0joQj7EMk"
      redirectUri:@"http://localhost"];
      break;
      default:
      break;
      }
      }];
      return YES;
      }

7.在你点击方法里面加入代码
//1、创建分享参数
NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];
(注意:图片必须要在Xcode左边目录里面,名称必须要传正确,如果要分享网络图片,可以这样传iamge参数 images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"])
if (imageArray) {

NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:@"分享内容"
images:imageArray
url:[NSURL URLWithString:@"http://mob.com"]
title:@"分享标题"
type:SSDKContentTypeAuto];
//2、分享(可以弹出我们的分享菜单和编辑界面)
[ShareSDK showShareActionSheet:nil //要显示菜单的视图, iPad版中此参数作为弹出菜单的参照视图,只有传这个才可以弹出我们的分享菜单,可以传分享的按钮对象或者自己创建小的view 对象,iPhone可以传nil不会影响
items:nil
shareParams:shareParams
onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {

switch (state) {
case SSDKResponseStateSuccess:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
message:nil
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
break;
}
case SSDKResponseStateFail:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
break;
}
default:
break;
}
}
];}

8.SSO授权登录

注。。。。。。。QQ的SSO授权的 URL Schemes 的 appkey 为16进制;微博分享需要在开发者账号上面申请应用,拿到ID,在微博开放平台上面相应地址填上就可以申请了。

你想要在哪个应用上面分享,你就要去哪个应用的开发平台申请应用,拿到相应的appkey 和 appSecret.

完毕——————。

posted @ 2016-09-28 16:30  懵懂少侠  阅读(1188)  评论(0)    收藏  举报