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

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

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

  1. #import "AppDelegate.h"
  2. #import "RootViewController.h"
  3. #import <ShareSDK/ShareSDK.h>
  4. #import "WeiboApi.h"
  5. #import <TencentOpenAPI/QQApiInterface.h>
  6. #import <TencentOpenAPI/TencentOAuth.h>
  7. #import "WXApi.h"
  8. #import <TencentOpenAPI/QQApiInterface.h>
  9. #import <TencentOpenAPI/TencentOAuth.h>
  10. @implementation AppDelegate
  11. @synthesize rootVC;
  12. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  13. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  14. if (self.rootVC==nil) {
  15. self.rootVC = [[RootViewController alloc]initWithNibName:@"RootViewController" bundle:nil];
  16. }
  17. UINavigationController *rootNav = [[UINavigationController alloc]initWithRootViewController:self.rootVC];
  18. self.window.rootViewController = rootNav;
  19. self.window.backgroundColor = [UIColor whiteColor];
  20. [self.window makeKeyAndVisible];
  21. <span style="color:#ff0000;">[ShareSDK registerApp:@"1a2e7ab5fb6c"];</span>
  22. <span style="color:#3366ff;"> //添加新浪微博应用 注册网址 http://open.weibo.com  wdl@pmmq.com 此处需要替换成自己应用的
  23. [ShareSDK connectSinaWeiboWithAppKey:@"3201194191"
  24. appSecret:@"0334252914651e8f76bad63337b3b78f"
  25. redirectUri:@"http://appgo.cn"];
  26. //添加腾讯微博应用 注册网址 http://dev.t.qq.com wdl@pmmq.com 此处需要替换成自己应用的
  27. [ShareSDK connectTencentWeiboWithAppKey:@"801307650"
  28. appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
  29. redirectUri:@"http://www.sharesdk.cn"
  30. wbApiCls:[WeiboApi class]];
  31. //添加QQ空间应用 注册网址  http://connect.qq.com/intro/login/ wdl@pmmq.com 此处需要替换成自己应用的
  32. [ShareSDK connectQZoneWithAppKey:@"100371282"
  33. appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
  34. qqApiInterfaceCls:[QQApiInterface class]
  35. tencentOAuthCls:[TencentOAuth class]];
  36. //此参数为申请的微信AppID wdl@pmmq.com 此处需要替换成自己应用的
  37. [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885" wechatCls:[WXApi class]];
  38. //添加QQ应用 该参数填入申请的QQ AppId wdl@pmmq.com 此处需要替换成自己应用的
  39. [ShareSDK connectQQWithQZoneAppKey:@"100371282"
  40. qqApiInterfaceCls:[QQApiInterface class]
  41. tencentOAuthCls:[TencentOAuth class]];</span>
  42. return YES;
  43. }
  44. - (void)applicationWillResignActive:(UIApplication *)application {
  45. // 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.
  46. // 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.
  47. }
  48. - (void)applicationDidEnterBackground:(UIApplication *)application {
  49. // 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.
  50. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  51. }
  52. - (void)applicationWillEnterForeground:(UIApplication *)application {
  53. // 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.
  54. }
  55. - (void)applicationDidBecomeActive:(UIApplication *)application {
  56. // 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.
  57. }
  58. - (void)applicationWillTerminate:(UIApplication *)application {
  59. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  60. }
  61. <span style="color:#ff6600;">#pragma mark - WX回调
  62. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
  63. return [ShareSDK handleOpenURL:url wxDelegate:self];
  64. }
  65. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  66. return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
  67. }
  68. #pragma mark - WXApiDelegate
  69. /*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果
  70. *
  71. * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。
  72. * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。
  73. * @param req 具体请求内容,是自动释放的
  74. */
  75. -(void) onReq:(BaseReq*)req{
  76. }
  77. /*! @brief 发送一个sendReq后,收到微信的回应
  78. *
  79. * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。
  80. * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。
  81. * @param resp具体的回应内容,是自动释放的
  82. */
  83. -(void) onResp:(BaseResp*)resp{
  84. }
  85. </span>
  86. @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. #import "LoginViewController.h"
  2. #import <ShareSDK/ShareSDK.h>
  3. @interface LoginViewController ()
  4. -(IBAction)loginWithSina:(id)sender;
  5. -(IBAction)loginWithQQ:(id)sender;
  6. -(IBAction)loginoutWithSina:(id)sender;
  7. -(IBAction)loginoutWithQQ:(id)sender;
  8. -(IBAction)guanzhuUs:(id)sender;
  9. -(void)reloadStateWithType:(ShareType)type;
  10. @end
  11. @implementation LoginViewController
  12. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  13. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  14. if (self) {
  15. }
  16. return self;
  17. }
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. }
  21. - (void)didReceiveMemoryWarning {
  22. [super didReceiveMemoryWarning];
  23. }
  24. - (IBAction)loginWithSina:(id)sender {
  25. [ShareSDK getUserInfoWithType:ShareTypeSinaWeibo authOptions:nil result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
  26. NSLog(@"%d",result);
  27. if (result) {
  28. //成功登录后,判断该用户的ID是否在自己的数据库中。
  29. //如果有直接登录,没有就将该用户的ID和相关资料在数据库中创建新用户。
  30. [self reloadStateWithType:ShareTypeSinaWeibo];
  31. }
  32. }];
  33. }
  34. -(IBAction)loginWithQQ:(id)sender{
  35. [ShareSDK getUserInfoWithType:ShareTypeQQSpace authOptions:nil result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
  36. NSLog(@"%d",result);
  37. if (result) {
  38. //成功登录后,判断该用户的ID是否在自己的数据库中。
  39. //如果有直接登录,没有就将该用户的ID和相关资料在数据库中创建新用户。
  40. [self reloadStateWithType:ShareTypeQQSpace];
  41. }
  42. }];
  43. }
  44. -(IBAction)loginoutWithSina:(id)sender{
  45. [ShareSDK cancelAuthWithType:ShareTypeSinaWeibo];
  46. [self reloadStateWithType:ShareTypeSinaWeibo];
  47. }
  48. -(IBAction)loginoutWithQQ:(id)sender{
  49. [ShareSDK cancelAuthWithType:ShareTypeQQSpace];
  50. [self reloadStateWithType:ShareTypeQQSpace];
  51. }
  52. -(void)reloadStateWithType:(ShareType)type{
  53. //现实授权信息,包括授权ID、授权有效期等。
  54. //此处可以在用户进入应用的时候直接调用,如授权信息不为空且不过期可帮用户自动实现登录。
  55. id<ISSPlatformCredential> credential = [ShareSDK getCredentialWithType:type];
  56. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"TEXT_TIPS", @"提示")
  57. message:[NSString stringWithFormat:
  58. @"uid = %@\ntoken = %@\nsecret = %@\n expired = %@\nextInfo = %@",
  59. [credential uid],
  60. [credential token],
  61. [credential secret],
  62. [credential expired],
  63. [credential extInfo]]
  64. delegate:nil
  65. cancelButtonTitle:NSLocalizedString(@"TEXT_KNOW", @"知道了")
  66. otherButtonTitles:nil];
  67. [alertView show];
  68. }
  69. //关注用户
  70. -(IBAction)guanzhuUs:(id)sender{
  71. [ShareSDK followUserWithType:ShareTypeSinaWeibo         //平台类型
  72. field:@"ShareSDK"                //关注用户的名称或ID
  73. fieldType:SSUserFieldTypeName        //字段类型,用于指定第二个参数是名称还是ID
  74. authOptions:nil                        //授权选项
  75. viewDelegate:nil                        //授权视图委托
  76. result:^(SSResponseState state, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
  77. if (state == SSResponseStateSuccess) {
  78. NSLog(@"关注成功");
  79. } else if (state == SSResponseStateFail) {
  80. NSLog(@"%@", [NSString stringWithFormat:@"关注失败:%@", error.errorDescription]);
  81. }
  82. }];
  83. }
  84. @end

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

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

(6)测试DEMO截图:

DEMO下载地址:http://download.csdn.net/download/daleiwang/7734321

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. MVC方式显示数据(数据库)

    新建实体数据模型 选择ADO.NET实体数据模型,名称改为数据库名 因为使用现有数据库,所以选择来自数据库的EF设计器,只演示所以只选择一个表,空模型可后期增加表 选择从数据库更新模型 新建数据库连接 ...

  2. php使用播放插件播放m3u8,mp4,flv格式的视频

    一.这里我主要是播放m3u8的视频,有两款比较好的插件,swise和ckpalyer,我介绍的是ckplayer,这是在pc端播放的,并且是需要flash支持的,不过现在的最新浏览器都是默认安装的 二 ...

  3. 熟记这些python内置函数,你离大佬就不远了

    python内置了很多函数,方便我们在写程序的时候调用,在ython 2.7 的所有内置函数共有80个.熟练记住和使用这些内置函数,将大大提高写Python代码的速度和代码的优雅程度. 以下代码示例用 ...

  4. 15_sqoop数据导出

    1.Sqoop的数据导出 将数据从HDFS导出到RDBMS数据库,导出前,目标表必须存在于目标数据库中 默认操作是将文件中的数据使用INSERT语句插入到表中 更新模式下,是生成UPDATE语句更新表 ...

  5. 浏览器获取当前ip

    function findIP(callback) { var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConn ...

  6. Excel 教程一

    俗话说,工欲善其事,必先利其器,那么我们今天就先来看一下这个excel软件的一些主要功能菜单. 一.功能区菜单 功能区菜单主要包括: 文件菜单:  主要用于新建文件,保存文件,另存为文件,打开文件,打 ...

  7. C#串口图片传输以及对串口缓冲区的简单理解

    第一次接触串口,写点东西加深自己对串口的印象: 通过参考一些网上的实例,我明白了串口怎么简单的进行通信交流,但是我所需要的还是图片等大文件在串口中的传输,串口传输是通过二进制位进行单位传输的,所以传输 ...

  8. 解决selenium和FireFox版本不兼容问题

    相信很多同学刚接触selenium时,在Eclipse中打开fireFox浏览器时会报错:org.openqa.selenium.firefox.NotConnectedException: Unab ...

  9. mybatis+redis实现二级缓存

    在网上看了很多资料,发现例子都是千篇一律的相互复制.而且,使用的都是jedis的客户端..我这里使用的是redistemplate类实现. 缓存的原理..实现cache类接口,当哪个类需要缓存的时候, ...

  10. 016_linux驱动之_原子操作

    1. 原子操作 原子操作指的是在执行过程中不会被别的代码路径所中断的操作. 常用原子操作函数举例: atomic_t v = ATOMIC_INIT(0);     //定义原子变量v并初始化为0 a ...