(1)官方下载ShareSDK iOS 2.8.8,地址:http://sharesdk.cn/

(2)根据实际情况,引入相关的库,参考官方文档

(3)在项目的AppDelegate中一般情况下有三个操作,第一是注册ShareSDK,第二是注册各个平台的账号,第三是关于微信等应用的回调处理。

  1. //
  2. //  AppDelegate.m
  3. //  ShareSDKTest
  4. //
  5. //  Created by wangdalei on 14-6-23.
  6. //  Copyright (c) 2014年 王大雷. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "RootViewController.h"
  10. #import <ShareSDK/ShareSDK.h>
  11. #import "WeiboApi.h"
  12. #import <TencentOpenAPI/QQApiInterface.h>
  13. #import <TencentOpenAPI/TencentOAuth.h>
  14. #import "WXApi.h"
  15. #import <TencentOpenAPI/QQApiInterface.h>
  16. #import <TencentOpenAPI/TencentOAuth.h>
  17. @implementation AppDelegate
  18. @synthesize rootVC;
  19. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  20. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  21. if (self.rootVC==nil) {
  22. self.rootVC = [[RootViewController alloc]initWithNibName:@"RootViewController" bundle:nil];
  23. }
  24. UINavigationController *rootNav = [[UINavigationController alloc]initWithRootViewController:self.rootVC];
  25. self.window.rootViewController = rootNav;
  26. self.window.backgroundColor = [UIColor whiteColor];
  27. [self.window makeKeyAndVisible];
  28. <span style="color:#ff0000;">[ShareSDK registerApp:@"1a2e7ab5fb6c"];</span>
  29. <span style="color:#3366ff;"> //添加新浪微博应用 注册网址 http://open.weibo.com  wdl@pmmq.com 此处需要替换成自己应用的
  30. [ShareSDK connectSinaWeiboWithAppKey:@"3201194191"
  31. appSecret:@"0334252914651e8f76bad63337b3b78f"
  32. redirectUri:@"http://appgo.cn"];
  33. //添加腾讯微博应用 注册网址 http://dev.t.qq.com wdl@pmmq.com 此处需要替换成自己应用的
  34. [ShareSDK connectTencentWeiboWithAppKey:@"801307650"
  35. appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
  36. redirectUri:@"http://www.sharesdk.cn"
  37. wbApiCls:[WeiboApi class]];
  38. //添加QQ空间应用 注册网址  http://connect.qq.com/intro/login/ wdl@pmmq.com 此处需要替换成自己应用的
  39. [ShareSDK connectQZoneWithAppKey:@"100371282"
  40. appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
  41. qqApiInterfaceCls:[QQApiInterface class]
  42. tencentOAuthCls:[TencentOAuth class]];
  43. //此参数为申请的微信AppID wdl@pmmq.com 此处需要替换成自己应用的
  44. [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885" wechatCls:[WXApi class]];
  45. //添加QQ应用 该参数填入申请的QQ AppId wdl@pmmq.com 此处需要替换成自己应用的
  46. [ShareSDK connectQQWithQZoneAppKey:@"100371282"
  47. qqApiInterfaceCls:[QQApiInterface class]
  48. tencentOAuthCls:[TencentOAuth class]];</span>
  49. return YES;
  50. }
  51. - (void)applicationWillResignActive:(UIApplication *)application {
  52. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  53. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
  54. }
  55. - (void)applicationDidEnterBackground:(UIApplication *)application {
  56. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  57. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  58. }
  59. - (void)applicationWillEnterForeground:(UIApplication *)application {
  60. // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
  61. }
  62. - (void)applicationDidBecomeActive:(UIApplication *)application {
  63. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  64. }
  65. - (void)applicationWillTerminate:(UIApplication *)application {
  66. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  67. }
  68. <span style="color:#ff6600;">#pragma mark - WX回调
  69. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
  70. return [ShareSDK handleOpenURL:url wxDelegate:self];
  71. }
  72. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  73. return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
  74. }
  75. #pragma mark - WXApiDelegate
  76. /*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果
  77. *
  78. * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。
  79. * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。
  80. * @param req 具体请求内容,是自动释放的
  81. */
  82. -(void) onReq:(BaseReq*)req{
  83. }
  84. /*! @brief 发送一个sendReq后,收到微信的回应
  85. *
  86. * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。
  87. * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。
  88. * @param resp具体的回应内容,是自动释放的
  89. */
  90. -(void) onResp:(BaseResp*)resp{
  91. }
  92. </span>
  93. @end

(4)信息分享。

  1. -(IBAction)share:(id)sender{
  2. NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"card"  ofType:@"png"];
  3. //构造分享内容
  4. id<ISSContent> publishContent = [ShareSDK content:@"分享内容测试"
  5. defaultContent:@"默认分享内容测试,没内容时显示"
  6. image:[ShareSDK imageWithPath:imagePath]
  7. title:@"pmmq"
  8. url:@"http://www.sharesdk.cn"
  9. description:@"这是一条测试信息"
  10. mediaType:SSPublishContentMediaTypeNews];
  11. [ShareSDK showShareActionSheet:nil
  12. shareList:nil
  13. content:publishContent
  14. statusBarTips:YES
  15. authOptions:nil
  16. shareOptions: nil
  17. result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
  18. if (state == SSResponseStateSuccess)
  19. {
  20. NSLog(@"分享成功");
  21. }
  22. else if (state == SSResponseStateFail)
  23. {
  24. NSLog(@"分享失败");
  25. }
  26. }];
  27. }

(5)登录、登出、获取授权信息、关注制定微博

  1. //
  2. //  LoginViewController.m
  3. //  ShareSDKTest
  4. //
  5. //  Created by wangdalei on 14-6-23.
  6. //  Copyright (c) 2014年 王大雷. All rights reserved.
  7. //
  8. #import "LoginViewController.h"
  9. #import <ShareSDK/ShareSDK.h>
  10. @interface LoginViewController ()
  11. -(IBAction)loginWithSina:(id)sender;
  12. -(IBAction)loginWithQQ:(id)sender;
  13. -(IBAction)loginoutWithSina:(id)sender;
  14. -(IBAction)loginoutWithQQ:(id)sender;
  15. -(IBAction)guanzhuUs:(id)sender;
  16. -(void)reloadStateWithType:(ShareType)type;
  17. @end
  18. @implementation LoginViewController
  19. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  20. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  21. if (self) {
  22. }
  23. return self;
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. }
  28. - (void)didReceiveMemoryWarning {
  29. [super didReceiveMemoryWarning];
  30. }
  31. - (IBAction)loginWithSina:(id)sender {
  32. [ShareSDK getUserInfoWithType:ShareTypeSinaWeibo authOptions:nil result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
  33. NSLog(@"%d",result);
  34. if (result) {
  35. //成功登录后,判断该用户的ID是否在自己的数据库中。
  36. //如果有直接登录,没有就将该用户的ID和相关资料在数据库中创建新用户。
  37. [self reloadStateWithType:ShareTypeSinaWeibo];
  38. }
  39. }];
  40. }
  41. -(IBAction)loginWithQQ:(id)sender{
  42. [ShareSDK getUserInfoWithType:ShareTypeQQSpace authOptions:nil result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
  43. NSLog(@"%d",result);
  44. if (result) {
  45. //成功登录后,判断该用户的ID是否在自己的数据库中。
  46. //如果有直接登录,没有就将该用户的ID和相关资料在数据库中创建新用户。
  47. [self reloadStateWithType:ShareTypeQQSpace];
  48. }
  49. }];
  50. }
  51. -(IBAction)loginoutWithSina:(id)sender{
  52. [ShareSDK cancelAuthWithType:ShareTypeSinaWeibo];
  53. [self reloadStateWithType:ShareTypeSinaWeibo];
  54. }
  55. -(IBAction)loginoutWithQQ:(id)sender{
  56. [ShareSDK cancelAuthWithType:ShareTypeQQSpace];
  57. [self reloadStateWithType:ShareTypeQQSpace];
  58. }
  59. -(void)reloadStateWithType:(ShareType)type{
  60. //现实授权信息,包括授权ID、授权有效期等。
  61. //此处可以在用户进入应用的时候直接调用,如授权信息不为空且不过期可帮用户自动实现登录。
  62. id<ISSPlatformCredential> credential = [ShareSDK getCredentialWithType:type];
  63. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"TEXT_TIPS", @"提示")
  64. message:[NSString stringWithFormat:
  65. @"uid = %@\ntoken = %@\nsecret = %@\n expired = %@\nextInfo = %@",
  66. [credential uid],
  67. [credential token],
  68. [credential secret],
  69. [credential expired],
  70. [credential extInfo]]
  71. delegate:nil
  72. cancelButtonTitle:NSLocalizedString(@"TEXT_KNOW", @"知道了")
  73. otherButtonTitles:nil];
  74. [alertView show];
  75. }
  76. //关注用户
  77. -(IBAction)guanzhuUs:(id)sender{
  78. [ShareSDK followUserWithType:ShareTypeSinaWeibo         //平台类型
  79. field:@"ShareSDK"                //关注用户的名称或ID
  80. fieldType:SSUserFieldTypeName        //字段类型,用于指定第二个参数是名称还是ID
  81. authOptions:nil                        //授权选项
  82. viewDelegate:nil                        //授权视图委托
  83. result:^(SSResponseState state, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
  84. if (state == SSResponseStateSuccess) {
  85. NSLog(@"关注成功");
  86. } else if (state == SSResponseStateFail) {
  87. NSLog(@"%@", [NSString stringWithFormat:@"关注失败:%@", error.errorDescription]);
  88. }
  89. }];
  90. }
  91. @end

(5)你可能会看到一些应用需要第三方登录的,一种是弹出webView加载的新浪微博或者qq的网页授权,还有一种是跳转到本地的已经安装的新浪微博应用或者qq应用进行授权。第二种授权方式较SSO授权,体验会比较好一些,因为不需要用户输入新浪微博或QQ的用户名与密码。

第二种授权方式需要在plist中配置Scheme。SSO默认是打开的不需要配置。在AppDelegate中实现回调。

(6)测试DEMO截图:

IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。的更多相关文章

  1. IOS项目集成ShareSDK实现第三方登录、分享、关注等功能(备用)

    (1)官方下载ShareSDK iOS 2.8.8,地址:http://sharesdk.cn/ (2)根据实际情况,引入相关的库,参考官方文档. (3)在项目的AppDelegate中一般情况下有三 ...

  2. IOS项目集成ShareSDK实现第三方登录、分享、关注等功能

    (1)官方下载ShareSDK iOS 2.8.8,地址:http://sharesdk.cn/ (2)根据实际情况,引入相关的库,参考官方文档. (3)在项目的AppDelegate中一般情况下有三 ...

  3. iOS:IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。

    原文链接:http://blog.csdn.net/daleiwang/article/details/34081231 (3)在项目的AppDelegate中一般情况下有三个操作,第一是注册Shar ...

  4. iOS开发---集成ShareSDK实现第三方登录、分享、关注等功能。

    (1)官方下载ShareSDK IOS 2.9.6,地址:http://sharesdk.mob.com/Download (2)根据实际情况,引入相关的库,参考官方文档. (3)在项目的AppDel ...

  5. iOS:友盟SDK第三方登录 分享及友盟统计的使用

    本文转载至 http://www.it165.net/pro/html/201503/37101.html Tag标签:第三方   01.#import "UMSocial.h" ...

  6. iOS项目中常用的第三方开源库

    1.项目使用的第三方开源库 项目使用了CocoaPods(类似java中的maven)管理常用的第三方库,一些特殊的单独引用,下面介绍下比较好用的几个. (1)AFNetworking 目前比较推荐的 ...

  7. 现有iOS项目集成React Native过程记录

    在<Mac系统下React Native环境搭建>配置了RN的开发环境,然后,本文记录在现有iOS项目集成React Native的过程,官方推荐使用Cocoapods,项目一开始也是使用 ...

  8. php+redis实现注册、删除、编辑、分页、登录、关注等功能

    本文实例讲述了php+redis实现注册.删除.编辑.分页.登录.关注等功能.分享给大家供大家参考,具体如下: 主要界面 ​ 连接redis redis.php <?php //实例化 $red ...

  9. 利用ShareSDK进行第三方登录和分享

    到相应开发者平台注册开发者账号,并添加你要进行分享和使用第三方登录应用的信息. 添加新浪微博应用 注册网址 http://open.weibo.com添加QQ应用 注册网址  http://mobil ...

随机推荐

  1. 理解js中的自由变量以及作用域的进阶

    如果你不知道什么是作用域,建议你先看什么是作用域链,什么是原型链.这篇文章,因为这些内容都是有关联性的. 什么是自由变量? 如我在全局中定义了一个变量a,然后我在函数中使用了这个a,这个a就可以称之为 ...

  2. JavaScript 变量生命周期

    变量在它声明时初始化. 局部变量在函数调用时创建,当函数执行完毕后销毁,这和为什么要使用闭包也有一点关系,当然这是另外的话题了. 全局变量在页面(当前页面)关闭后销毁.

  3. ruby -- 问题解决(六)link_to to destroy not working

    在Rails的development环境下开发时,使用link_to进行destroy时顺利进行,最近将环境配置成production时,使用link_to,结果not working 代码如下: & ...

  4. 这些年你需要注意的SQL

    [20141114]这些年你需要注意的SQL *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bot ...

  5. 用emacs的org2blog组件写cnblogs博客 -- 环境配置及使用

    Table of Contents 配置 使用 创建一篇博文并发布 更新一篇博文 删除一篇博文 待办 本文给出了一个安装.配置org2blog的方法,实现在emacs中书写blog文章.并发布到cnb ...

  6. JS&CSS文件请求合并及压缩处理研究(二)

    上篇交待了一些理论方面的东西,并给出了另外一种解决方案的处理流程.本篇将根据该处理流程,开始代码方面的编写工作. 1,打开VS,新建ASP.NET MVC Web项目,项目类型选择空.名称为 Mcmu ...

  7. 快速清除文件夹svn版本控制信息

    将下面内容另存为clear.bat文件,在有版本控制的目录执行即可 @echo On @Rem 清除SVN版本控制信息 @for /r . %%a in (.) do @if exist " ...

  8. SQL Server 2014里的IO资源调控器

    在本文中,我们将来看看SQL Server 2014在资源调控器方面增加了哪些新的功能.资源调控器(Resource Governor)是从SQL Server 2008开始出现的一项功能.它是用于管 ...

  9. C#入门经典第五版之变量的更多内容编码题训练

    1. 编写一个控制台应用程序,它接收用户输入的一个字符串,将其中的字符以与输入相反的顺序输出. public string ReverseString(string str) { string rev ...

  10. Water --- CSU 1550: Simple String

    Simple String Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1550 Mean: 略. analy ...