• IOS 集成第三方登录


        

    本人开发的开发者技术变现资源聚集地,大家支持下,下面是网址

    https://www.baiydu.com

    我使用的是友盟上集成的第三方登录功能,一共使用了三个应用的登录授权,QQ、微信、新浪微博。由于第三方登录授权成功后,需要跳转到一个新的界面,所以这里需要在项目里设置第三方登录的SSO授权。就是必须安装了相关的手机客户端后,才能使用第三方登录,在使用第三方登录时,我们需要先判断一下用户手机上是否已经安装了对应的应用。

    一、集成SSO授权

        这里集成SSO授权的方法我就不详细讲解了,因为还涉及到注册第三方平台帐号这些琐屑的事。下面我给一个友盟上集成SSO授权的地址,文档说明都是很详细的

    地址:http://dev.umeng.com/social/ios/detail-share#6  如果你中途遇到任何问题,都可以在这里留言,接下去我主要是贴代码和实现效果截图。

    二、第三方登录实现代码

    这里首先需要实现功能的ViewController中引入对应的库

    #import "UMSocial.h"

    #import "WXApi.h" 

    #import <TencentOpenApi/QQApiInterface.h> 

    #import "WeiboSDK.h"

    下面的方法就是就是上面代码中UIImageView  *shareButton绑定的手势,这里为什么要使用UIImageView,

    因为我代码布局中 shareButton的宽度和高度没有固定,是根据屏幕的宽度来计算的,如果使用UIButton就会出现

    贴的图片的大小不会随着动态计算出的高宽而缩放  1 //公用的跳转用户资料详情页面

      1 //公用的跳转用户资料详情页面
      2 -(void)thirdSDKLogin:(UITapGestureRecognizer *)sender
      3 
      4 {
      5     UIImageView *view=(UIImageView *)sender.self.view;
      6     if (view.tag==123456 ) {
      7         //判断微信客户端是否安装
      8         if ([WXApi isWXAppInstalled]) {
      9             NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeWechatSession];
     10             
     11             UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];
     12             
     13             snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
     14                 
     15                 NSLog(@"login response is %@",response);
     16                 
     17                 //获取微博用户名、uid、token等
     18                 
     19                 if (response.responseCode == UMSResponseCodeSuccess) {
     20                     
     21                     UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];
     22                     
     23                     NSLog(@"username is %@, uid is %@, token is %@,iconUrl is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
     24                     
     25                 }
     26                 
     27             });
     28         }
     29         else
     30         {
     31             showMessage(@"请先安装微信客户端。");
     32             return;
     33         }
     34 
     35     }
     36      else if(view.tag==123457)
     37      {
     38          //判断qq客户端是否安装
     39          if ([QQApiInterface isQQInstalled]) {
     40              NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeMobileQQ];
     41              
     42              UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
     43              
     44              snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
     45                  
     46                  NSLog(@"login response is %@",response);
     47                  
     48                  //获取微博用户名、uid、token等
     49                  
     50                  if (response.responseCode == UMSResponseCodeSuccess) {
     51                      
     52                      UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];
     53                    NSLog(@"username is %@, uid is %@, token is %@,iconUrl is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
     54                      
     55                  }
     56                  
     57              });
     58          }
     59          else{
     60              showMessage(@"请先安装qq客户端。");
     61              return;
     62          }
     63      }
     64      else
     65      {
     66          
     67          //判断sina客户端是否安装
     68          if ([WeiboSDK isCanShareInWeiboAPP])
     69              
     70          {
     71              /*新浪登录第三方登录授权*/
     72              NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeSina];
     73              UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
     74              
     75              snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
     76                  
     77                  NSLog(@"response is %@",response);
     78                  
     79                  if (response.responseCode == UMSResponseCodeSuccess) {
     80                      
     81                      UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];
     82                      
     83                      NSLog(@"=========%@",snsAccount.accessToken);
     84                      
     85                  }
     86                  
     87              });
     88 
     89              
     90          }
     91          
     92          else
     93              
     94          {
     95              
     96              showMessage(@"请先安装新浪微博客户端。");
     97              return;
     98              
     99              
    100          }
    101      }
    102 }

     本人创业做的一款androidApp, 下载量已经有2000多万,各种当前热门的网络手机奖励红包全部集成,另外还有热门电影和淘宝高额优惠券!很适合各类型的用户。

      

  • 相关阅读:
    第二篇 Flask 中的 Render Redirect HttpResponse
    第一篇 你好,我叫Flask
    redis发布订阅
    redis学习
    mysql+centos7+主从复制
    Linux系统基础优化及常用命令
    vim与程序员
    Shell基本命令
    js bom和dom
    javaScript基础
  • 原文地址:https://www.cnblogs.com/xiaoliao/p/5125611.html
Copyright © 2020-2023  润新知