Based on the iOS implementation of the app's third-party landing QQ and Sina Weibo licensing, in the development of clearly feel the difference between the two SDK and ease of use, here first to the third-party SDK access to a basic step:
1, to determine the need for such a function, if QQ login, it seems mainstream, app registration standard AH;
2, find relevant open platform, such as QQ interconnection platform, http://connect.qq.com/;
3, after the successful registration to create their own app, fill in a bunch of basic signals to get a app_key, is your app's unique identification code;
3, download the corresponding SDK, and read the development document or demo, usually look at the development of the document is more intuitive, if you look at the demo, some of the SDK's demo simply can't bear to stare;
4, embed the corresponding function in the SDK, after the successful Test submitted third party platform audit, and so on after the audit can be formally access to the third-party SDK function;
5, complete all functions and submit appstore audit it, about a week or so.
Well, say so much, let us enter the QQ login and Sina Weibo login authorization specific operation, this simple login method greatly simplifies the user's registration, but also extends the social nature of the app, more easy to share and promote, after login can get the user's unique ID, only the app background binding this ID, is equal to the user registration of the app, it seems to become the main application of the standard login mode, spit groove, it seems that the drawer design slowly change back to the Tabbar type, specific reasons can refer to network resources.
One, QQ login authorization development:
1, follow the development document into the SDK, and then add the key to the URL schemes after the successful registration, for example: tencent1101737816, note that these documents are written clearly;
2, in the APPDELEGATE.M implementation of the following methods, note, directly copy the code, both write one, of course, don't forget to introduce the header file, which is used as a return to the app callback function
<span style= "FONT-SIZE:14PX;" ><span style= "FONT-SIZE:14PX;" >-(BOOL) Application: (UIApplication *) application OpenURL: (nsurl *) URL sourceapplication: (NSString *) sourceapplication annotation: (ID) annotation{ return [Tencentoauth Handleopenurl:url];} -(BOOL) Application: (UIApplication *) application Handleopenurl: (Nsurl *) url{ return [Tencentoauth handleopenurl: URL];} </span></span>
3, register and authorize, pay attention to authorization there will be problems
_tencentoauth = [[Tencentoauth alloc] Initwithappid:kqq_key anddelegate:self]; Registered
<span style= "FONT-SIZE:14PX;" > Nsarray *_permissions = [Nsarray arraywithobjects:kopen_permission_get_info, Kopen_permission_get_user_info, Kopen_permission_get_simple_user_info, nil]; [_tencentoauth authorize:_permissions Insafari:no]; Licensing </span>
Note: The authorization code mentioned in the official documentation is: _permissions = [[Nsarray arraywithobjects:@ "Get_user_info", @ "add_t", Nil] retain];//Official Authorization Code
If you write like this, you will find always login not, prompt permission is not enough, very pit dad, correct authorization code such as the above wording, remember
4, the implementation of the successful login callback function, the implementation of protocol Tencentsessiondelegate, the code is as follows:
<span style= "FONT-SIZE:14PX;" ><span style= "FONT-SIZE:18PX;" >-(void) tencentdidlogin{ _labeltitle.text = @ "Login complete"; if (_tencentoauth.accesstoken && 0! = [_tencentoauth.accesstoken length]) { // record login user's OpenID, Token and expiry time _labelaccesstoken.text = _tencentoauth.accesstoken; } else{ _labelaccesstoken.text = @ "Login unsuccessful did not get Accesstoken"; }} -(void) Tencentdidnotlogin: (BOOL) cancelled{ if (cancelled) { _labeltitle.text = @ "User cancels login";} else{ _labeltitle.text = @ "Login failed";}} -(void) Tencentdidnotnetwork{[email protected] "No network connection, please set up the network"; </span></span>
5, if the code can go to login completed here, and obtained accesstoken, that means our login process is gone, the rest of the old is to obtain user-specific information, such as nicknames, cities and so on;
6, how to get a nickname, the document provides such a method
<span style= "FONT-SIZE:14PX;" ><span style= "FONT-SIZE:18PX;" > [_tencentoauth getuserinfo];</span></span>
But the return type is a bool similar, many friends are depressed, this is what situation, after looking at the code, found that if the developer calls this method, if successful will implement the following protocol Tencentsessiondelegate inside the callback function:
<span style= "FONT-SIZE:14PX;" ><span style= "FONT-SIZE:18PX;" >-(void) Getuserinforesponse: (Apiresponse *) response{// NSLog (@ "respons:%@", response.jsonresponse); Self.name.text = [Response.jsonresponse objectforkey:@ "nickname"];} </span></span>
this will be able to get the nickname we want, and so on, even if the completion of our QQ login authorization, the rest is to send backstage these login information, and keep the token after the successful authorization, see Official document description.
Second, Sina Weibo login authorization development:
1, same as QQ, configuration URL schemes, such as: wb2045436852, and then according to the official document access to the SDK and other information;
2, the following callback is also implemented in APPDELEGATE.M:
<span style= "FONT-SIZE:14PX;" >-(BOOL) Application: (UIApplication *) application OpenURL: (nsurl *) URL sourceapplication: (NSString *) sourceapplication annotation: (ID) annotation{ return [Tencentoauth Handleopenurl:url] | | [Weibosdk Handleopenurl:url delegate:self];} -(BOOL) Application: (UIApplication *) application Handleopenurl: (Nsurl *) url{ return [Tencentoauth handleopenurl: URL] | | [Weibosdk Handleopenurl:url delegate:self];} </span>
3, the successful login callback for Sina Weibo is written in this class, because the self is written here, and if you need to implement it in another class, you can modify it here.
<span style= "FONT-SIZE:14PX;" >[WEIBOSDK Handleopenurl:url delegate:self];</span>
the protocol implemented is: Weibosdkdelegate, protocol method:
<span style= "FONT-SIZE:14PX;" >-(void) Didreceiveweiboresponse: (Wbbaseresponse *) response{ if ([Response Iskindofclass: Wbauthorizeresponse.class]) { if ((int) Response.statuscode = = 0) { nsdictionary *dic = @{@ "UserID": [( Wbauthorizeresponse *) Response UserID], @ "Accesstoken": [(Wbauthorizeresponse *) response Accesstoken]};}} </span>
If you can get this userid,token it means that the login was successful.
4, Login code:
<span style= "FONT-SIZE:14PX;" >-(ibaction) Sinalogin: (ID) sender{ [Weibosdk Enabledebugmode:yes]; [Weibosdk Registerapp:ksina_key]; Wbauthorizerequest *request = [wbauthorizerequest request]; Request.redirecturi = Kredirecturi; Request.scope = @ "All"; Request.userinfo = @{@ "MyKey": @ "MyValue"}; [Weibosdk sendrequest:request];} </span>
This contains the registration, open debug log, also includes a callback address, user-defined submitted info, etc., if the login can correctly callback appdelegate inside the receive function, indicating that our bride Weibo login is also successful, the rest is to save the relevant information and submitted to the background, It is worth noting that if your bundle identifier to the same time as the application key, otherwise modify your demo bundle identifier for Sina Weibo official demo bundle identifier, and use its key to do the test, After the success of their application can be replaced again debugging;
Rating: Two platform access after the implementation of the function are very rich, but from the developer's point of view, QQ login authorization method compared to relatively simple, integration testing time is less, but the demo code is very ugly understand, even the official documents have code misleading, make debugging unusually difficult, And Sina Weibo login authorization Demo code is very simple and clear, very easy to understand, in this code writing, Sina Weibo developers better than QQ developers a few streets, but Sina Weibo login successful callback write relatively backward, need to get inside the appdelegate, no QQ callback convenient, and Sina Login Authorization binding bundle identifier, here let a person very puzzling, time-consuming test very uncomfortable, two style different bar, but overall is smooth, of course, if do not want to separate integration two login authorization, can recommend Baidu development platform to integrate their login SDK , this SDK integrates the major mainstream platforms, such as QQ, Sina Weibo, Renren, etc.
Here is the post-success:
PostScript: Here is just for the same development of friends to provide a little bit of the author's development problems encountered, such as QQ and Sina Weibo authorized login demo code, can send e-mail to me: [email protected], further discussion.
iOS code analysis based on third-party QQ authorized login and Sina Weibo authorized login