IOS authorized logon based on third-party QQ

Source: Internet
Author: User

IOS authorized logon based on third-party QQ

The following is a basic step for iOS APP third-party QQ login to access third-party sdks:

1, find the relevant open platform, QQ platform, http://connect.qq.com /;

2. After successful registration, create your own APP. Fill in a bunch of basic signals and obtain an App_Key, which is the unique identifier of your APP;

3. Download the corresponding SDK and read the development documentation or demo. Generally, the development documentation is intuitive. If you look at the demo, some SDK demos cannot be directly viewed;

4. embed the corresponding function in the SDK. After the test is successful, the function is submitted to a third-party platform for review. After the verification is passed, the function of the third-party SDK can be formally integrated;

5. Submit the App Store for review after completing all functions. It may take about a week.


1. Authorized QQ login development:

1. Import the SDK according to the development documents and add the Key obtained after registration to the Url Schemes. For example, tencent110172.1616. Note that these documents are clearly written;

2. Implement the following method in AppDelegate. m. Note that you can directly copy the code and write either of them. Of course, do not forget to introduce the header file. This is the callback function used to return the APP.

- (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];}

3. Register and authorize. Note that problems may occur during authorization.

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]; // authorization

4. Implement the callback function for Logon success or failure, and implement the TencentSessionDelegate protocol. The Code is as follows:

-(Void) tencentDidLogin {_ labelTitle. text = @ "Logon completed"; if (_ tencentOAuth. accessToken & 0! = [_ TencentOAuth. accessToken length]) {// record the login user's OpenID, Token, and expiration time _ labelAccessToken. text = _ tencentOAuth. accessToken;} else {_ labelAccessToken. text = @ "the logon fails. The accesstoken is not obtained." ;}}-(void) tencentDidNotLogin :( BOOL) canceled {if (canceled) {_ labelTitle. text = @ "";} else {_ labelTitle. text = @ "Logon Failed" ;}}- (void) tencentDidNotNetWork {_ labelTitle. text = @ "No network connection, please set the network ";}

5. If the code can be accessed and the accesstoken is obtained, the logon process is complete. The remaining information is used to obtain the user's specific information, such as the nickname, cities;

6. How can I get a nickname? The document provides this method.

[_tencentOAuth getUserInfo];

However, the return type is similar to BOOL, and many friends are depressed. What is the problem? after reading the code, I found that if the developer calls this method, if it succeeds, the callback function in the TencentSessionDelegate Protocol below will be implemented:

-(void)getUserInfoResponse:(APIResponse *)response{ //   NSLog(@"respons:%@",response.jsonResponse);         self.name.text = [response.jsonResponse objectForKey:@"nickname"];}

In this way, we can get the nickname and other information we want. Here, even if our QQ login authorization is completed, the rest is to send the login information to the background, and keep the token after the authorization is successful. Read the instructions in the official documentation.

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.