shareSDK使用

来源:互联网 发布:python 多线程 返回值 编辑:程序博客网 时间:2024/05/18 12:33


使用的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];

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


0 0