IOS:SHARESDK third-party login

Source: Internet
Author: User

SHARESDK third-party login is similar to sharing, relatively simple, before the introduction. Here's a simple way to write a third-party login.

1, first: I used the QQ, Sina, three platform login, need to their respective developer platform registered developer account, this is my QQ creation application, because there is no app icon imported, so not approved, but will still generate the available AppID and app KEY, You can then complete the information to submit your review.

2. Second: Download the SHARESDK package and import the required files into the project. It is recommended to use Cocoapods, which can directly help to import all dependent libraries to avoid trouble. The format I imported is as follows:

Pod ' ShareSDK3 '

Pod ' mobfoundation '

Pod ' SHARESDK3/SHARESDKPLATFORMS/QQ '

Pod ' Sharesdk3/sharesdkplatforms/sinaweibo '

Pod ' Sharesdk3/sharesdkplatforms/wechat '

3, then: use each platform Appkey or AppID to register the SHARESDK application, the code is as follows:

@implementationappdelegate (KJSHARESDK)-(void) Shareapplication: (uiapplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions{/** * Set SHARESDK Appkey, if not already registered in the SHARESDK website app, please move to the Http://mob.com/login login background for application registration, * in the generated appkey into this method. * The second third parameter in the method is triggered when the social Platform SDK needs to be connected, * The connection code is written in this event.     The fourth parameter is triggered when a local social platform is configured, and platform information is configured based on the type of platform returned.     * If you are using the server-side hosted platform information, the second to fourth parameter can pass in nil, and the third parameter determines the social SDK to connect based on the server-side hosting platform. */[Sharesdk registerapp:sharesdk_appkey activeplatforms:@[@ (ssdkplatformty                 Pesinaweibo), @ (Ssdkplatformtypewechat), @ (SSDKPLATFORMTYPEQQ)] Onimport:^(Ssdkplatformtype platformtype) {Switch(platformtype) { Casessdkplatformtypewechat: [Sharesdkconnector connectwechat:[wxapiclass]];  Break;  Casessdkplatformtypeqq: [Sharesdkconnector connectqq:[qqapiinterfaceclass] Tencentoauthclass:[tencentoauthclass]];  Break;  CaseSsdkplatformtypesinaweibo: [Sharesdkconnector connectweibo:[weibosdkclass]];  Break; default:                  Break; }} onconfiguration:^ (Ssdkplatformtype platformtype, Nsmutabledictionary *appInfo) {                  Switch(platformtype) { CaseSsdkplatformtypesinaweibo://set up Sina Weibo app information, where AuthType is set to authorize with Sso+web form[AppInfo Ssdksetupsinaweibobyappkey:sinawiebo_appkey appse                                            Cret:sinawiebo_appsecret Redirecturi:sinawiebo_redirecturi                 Authtype:ssdkauthtypeboth];  Break;  Casessdkplatformtypewechat: [AppInfo ssdksetupwechatbyappid:wechat_appid                 Appsecret:wechat_appsecret];  Break;  Casessdkplatformtypeqq: [AppInfo ssdksetupqqbyappid:qq_appid AppKey:                 Qq_appkey Authtype:ssdkauthtypeboth];  Break; default:                  Break; }     }];}@end

4, then: Go to the project under the info URL types set Whitelist, to support the client's jump, the following official:

It's mine:

6, start to call the integrated method, three-party login can, as long as the code is as follows:

Method One:

//For example, QQ login[sharesdk getuserinfo:ssdkplatformtypeqq onstatechanged:^ (ssdkresponsestate state, Ssdkuser *user, Nserror *error) {         if(state = =ssdkresponsestatesuccess) {NSLog (@"uid=%@", User.uid); NSLog (@"%@", user.credential); NSLog (@"token=%@", User.credential.token); NSLog (@"nickname=%@", User.nickname);
       To implement the app interface jump in this area:
1. If the user will QQ and the app has been bound, the direct login success can get the user's data;
2. If the user does not bind the QQ and the app, then the binding succeeds to obtain tokens from the server, the token is used to obtain the user data, it is very important.
In short: Each user has their own unique identity, using a third-party login, the third party does not know the user's account and password, then the user must first bind, the binding succeeds, the server returns the identity, then the server through this identity to obtain the user's data.
Else {NSLog (@ "%@", error);}];

Method Two:

/Import Header File#import<ShareSDKExtension/SSEThirdPartyLoginHelper.h>[Ssethirdpartyloginhelper loginbyplatform:ssdkplatformtypeqq onusersync:^ (Ssdkuser *user, Sseuserassociatehandler Associatehandler) {                                        //in this callback, the social platform user information can be bound to its own user system, and finally a unique user ID is used to correlate this user information. //in this example, it is not associated with a user system, then a social user is used to correspond to a system user. The UID of the social user is passed into the Associatehandler as the Association ID. Associatehandler (user.uid, user, user); NSLog (@"dd%@", User.rawdata); NSLog (@"dd%@", user.credential); } Onloginresult:^ (ssdkresponsestate state, Ssebaseuser *user, Nserror *error) {                                     if(state = =ssdkresponsestatesuccess) {                                     } }];

IOS:SHARESDK third-party login

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.