Third-party logon for IOS Integration and third-party login for ios Integration

Source: Internet
Author: User

Third-party logon for IOS Integration and third-party login for ios Integration

I used the third-party login function integrated on umeng. I used logon authorization for three applications, QQ, and Sina Weibo. After the third-party login authorization is successful, you need to jump to a new interface, so here you need to set third-party login SSO authorization in the project. Third-party login is only possible after the relevant mobile client is installed. When using a third-party login, we need to first determine whether the corresponding application has been installed on the user's mobile phone.

1. Integrate SSO authorization

Here, I will not explain in detail how to integrate SSO authorization, because it also involves the registration of third-party platform accounts. The following is an address for integrating SSO authorization on umeng. The instructions are very detailed.

Address: http://dev.umeng.com/social/ios/detail-share#6 if you encounter any problem midway, you can leave a message here, next I mainly paste code and implementation effect.

2. layout code of the corresponding control

1 NSArray * imageArray = [[NSArray alloc] initWithObjects: @ "btn_3_weixin", @ "btn_3_qq", @ "btn_3_weibo", nil]; 2 UIImageView * shareButton; 3 CGFloat firstButtonWdith = 0; 4 CGFloat axisY = functionButton. frame. origin. y + functionButton. frame. size. height + 40; 5 CGFloat thisWidht = DEVICE_Width-76; 6 7 UILabel * thisShareLabel; 8 for (int sh = 0; sh <3; sh ++) {9 shareButton = [[UIImageView alloc] init]; 10 if (sh = 0) {11 thisShareLabel = [[UILabel alloc] initWithFrame: CGRectMake (38, axisY + 7, thisWidht * 0.25, 1)]; 12 thisShareLabel. backgroundColor = [UIColor whiteColor]; 13 shareButton. frame = CGRectMake (thisShareLabel. frame. origin. x + thisShareLabel. frame. size. width * 0.18, thisShareLabel. frame. origin. y + 20, thisShareLabel. frame. size. width * 0.64, thisShareLabel. frame. size. width * 0.64); 14 15 firstButtonWdith = shareButton. frame. size. width; 16 17} 18 else if (sh = 1) 19 {20 thisShareLabel = [[UILabel alloc] initWithFrame: CGRectMake (thisShareLabel. frame. size. width + thisShareLabel. frame. origin. x, axisY, thisWidht * 0.5, 14)]; 21 thisShareLabel. text = @ "third-party Account Logon"; 22 23 shareButton. frame = CGRectMake (thisShareLabel. frame. origin. x + thisShareLabel. frame. size. width/2-(firstButtonWdith/2), thisShareLabel. frame. origin. y + 26, firstButtonWdith, firstButtonWdith); 24 25} 26 else27 {28 thisShareLabel = [[UILabel alloc] initWithFrame: CGRectMake (thisShareLabel. frame. size. width + thisShareLabel. frame. origin. x, axisY + 7, thisWidht * 0.25, 1)]; 29 thisShareLabel. backgroundColor = [UIColor whiteColor]; 30 31 shareButton. frame = CGRectMake (thisShareLabel. frame. origin. x + thisShareLabel. frame. size. width * 0.18, thisShareLabel. frame. origin. y + 20, thisShareLabel. frame. size. width * 0.64, thisShareLabel. frame. size. width * 0.64); 32} 33 thisShareLabel. font = [UIFont systemFontOfSize: 14]; 34 thisShareLabel. textAlignment = NSTextAlignmentCenter; 35 thisShareLabel. textColor = [UIColor whiteColor]; 36 [self addSubview: thisShareLabel]; 37 38 [shareButton setImage: [UIImage imageNamed: [imageArray objectAtIndex: sh]; 39 shareButton. userInteractionEnabled = YES; 40 bytes * Records = [[initalloc] initWithTarget: self action: @ selector (thirdSDKLogin :)]; 41 [shareButton addGestureRecognizer: timer]; 42 shareButton. tag = 123456 + sh; 43 [self addSubview: shareButton]; 44 if (sh = 2) {45 self. backScrollView. scrollEnabled = YES; 46 if (DEVICE_Height <500) {47 [self. backScrollView setContentSize: CGSizeMake (DEVICE_Width, self. backScrollView. contentSize. height + 50)]; 48} 49} 50 51 52}

 

 

The above is of course only part of the code of the third-party logon block on the logon interface. It is relative to the last control functionButton. The following figure shows the layout effect.

Iii. Third-party login implementation code

First, we need to introduce the corresponding library in ViewController to implement the function.

# Import "UMSocial. h"

# Import "WXApi. h"

# Import <TencentOpenApi/QQApiInterface. h>

# Import "WeiboSDK. h"

The following method is the gesture bound by UIImageView * shareButton in the code above. Why is UIImageView used here,

In my code layout, the width and height of shareButton are not fixed and are calculated based on the screen width. If UIButton is used

The size of the pasted image does not scale with the height and width dynamically calculated. If you write code to zoom in or out, the image will be blurred.

1 // public jump to user information details page 2-(void) thirdSDKLogin :( UITapGestureRecognizer *) sender 3 4 {5 UIImageView * view = (UIImageView *) sender. self. view; 6 if (view. tag = 123456) {7 // determine whether the client is installed 8 if ([WXApi isWXAppInstalled]) {9 NSString * platformName = [UMSocialSnsPlatformManager getSnsPlatformString: UMSocialSnsTypeWechatSession]; 10 11 UMSocialSnsPlatform * snsPlatform = [UMSocialSnsPlatformManager getSocialPlatform WithName: UMShareToWechatSession]; 12 13 snsPlatform. loginClickHandler (self, [UMSocialControllerService defaultControllerService], YES, ^ (UMSocialResponseEntity * response) {14 15 NSLog (@ "login response is % @", response ); 16 17 // get Weibo user name, uid, token, etc. 18 19 if (response. responseCode = UMSResponseCodeSuccess) {20 21 UMSocialAccountEntity * snsAccount = [[UMSocialAccountManager socialAccountDictionary] valu EForKey: 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 (@ "Please install the client first. "); 32 return; 33} 34 35} 36 else if (view. tag = 123457) 37 {38 // determine whether the qq client is installed 39 if ([QQApiInterface isQQInstalled]) {40 NSString * platformName = [UMSocialSnsPlatformManager getSnsPlatformString: UMSocialSnsTypeMobileQQ]; 41 42 UMSocialSnsPlatform * snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName: UMShareToQQ]; 43 44 snsPlatform. loginClickHandler (self, [UMSocialControllerService d EfaultControllerService], YES, ^ (UMSocialResponseEntity * response) {45 46 NSLog (@ "login response is % @", response ); 47 48 // get Weibo username, uid, token, etc. 49 50 if (response. responseCode = Response) {51 52 UMSocialAccountEntity * snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey: platformName]; 53 NSLog (@ "username is % @, uid is % @, token is % @, iconUrl is % @ ", snsAccount. user Name, snsAccount. usid, snsAccount. accessToken, snsAccount. iconURL); 54 55} 56 57}); 58} 59 else {60 showMessage (@ "Please install the qq client first. "); 61 return; 62} 63} 64 else 65 {66 67 // determine whether the sina client is installed 68 if ([WeiboSDK isCanShareInWeiboAPP]) 69 70 {71/* Sina third-party logon authorization */72 NSString * platformName = [Login getSnsPlatformString: UMSocialSnsTypeSina]; 73 UMSocialSnsPlatform * snsPlatform = [Login authorization: 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 showM Essage (@ "Install the Sina Weibo client first. "); 97 return; 98 99 100} 101} 102}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.