本人開發的開發者技術變現資源聚集地,大家支持下,下面是網址
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多萬,各種當前熱門的網絡手機獎勵紅包全部集成,另外還有熱門電影和淘寶高額優惠券!很適合各類型的用戶。