IOS QQ login Fool type integration

Source: Internet
Author: User
Tags openid

one, iOS SDK download please go to the SDK download page to download the latest version of QQ login IOS SDK. Two, iOS SDK directory structure iOS SDK package with two files: 1. Tencentopenapi.framework packaged the header file definition and implementation for the iOS SDK. 2. Tencentopenapi_ios_bundle.bundle packaged the resource files required by the IOS SDK. Third, add the iOS SDK files to the project in 1. Copy the Tencentopenapi.framework and Tencentopenapi_ios_bundle.bundle files from the IOS SDK to the app development directory. Then drag the tencentopenapi.framework from the Save directory of the SDK to the frameworks virtual directory in the Project Navigation view (Project Navigator).   2. In the popup dialog box, tick "Create groups for any added folders", remove "copy items into destination group ' s folder (if needed)" in the Add To targets, click Finish after selecting Target to join the SDK. 
once completed, the iOS SDK framework files were added to the development project. 3. Add the System library files that the SDK relies on. respectively, "Security.framework", "Libiconv.dylib", "Systemconfiguration.framework", "Coregraphics.framework", " Libsqlite3.dylib "," Coretelephony.framework "," Libstdc++.dylib "," Libz.dylib ". Open the project configuration file in Xcode and select the "Summary" column. 4. Select the "Linked Frameworks and Libraries" column in "Summary" and click the "+" icon. 5. Directly select the default library file and click "Add" to add "systemconfiguration.framework" as example 6. When you return, you see that "Systemconfiguration.framework" appears in "Linked Frameworks and Libraries". 7. Open the project configuration file in Xcode and select the "Build Phases" column. 8. Modify the necessary engineering configuration properties. In the "Build Settings" column in the project configuration, locate the "linking" configuration area and add the property value "-fobjc-arc" to the "other Linker Flags" configuration item. Four, modify the necessary Code 4.1 modify the project configuration file in Xcode, select your project settings, select the "TARGETS" column, in the "Info" tab, "URL type" to add a new "URL scheme", the new scheme = Tencent + AppID If you are using XCODE3 or a lower version, you will need to add it in the Plist file. The AppID we registered in the demo is 222222. If another project is created in Xcode 6.0, the bundle Display Name property value may not be set individually by default. But because the SDK needs to use the value of the bundle display name, be sure to check to make sure that this property exists, if not added on. 4.2 Overriding Appdelegate's Handleopenurl and OpenURL methods openurl:-(BOOL) Application: (UIApplication *) application OpenURL: (Nsurl *) URL sourceapplication: (NSString *) sourceapplication annotation: (ID) Annotation{return [tencentoauth Handleopenurl: URL];} handleopenurl:-(BOOL) Application: (UIApplication *) application Handleopenurl: (Nsurl *) Url{return [TencentOAuth Handleopenurl:url];} 4.3 Implementing methods in the Tencentsessiondelegate protocol in code specific protocols you can initialize the iOS SDK with reference to TENCENTOAUTH.H file 4.4 in Tencentopenapi.framework/headers API data Object Tencentoauth. (1) Create a tencentoauth and initialize its appid,demo to 222222. Delegate for implementing Tencentsessiondelegate object:  _tencentoauth = [Tencentoauth alloc] initwithappid:@ "222222",   anddelegate:self];  here delegate cannot be empty (2) Initialize Redirecturi (Here you need to fill in the domain name when registering the app. The default is no need to fill out. It is not recommended to fill in. The address registered in the demo is "www.qq.com"):  _tencentoauth.redirecturi = @ "www.qq.com";  (3) Sets the list of APIs that the app requires user authorization.   (it is recommended that if there is too much authorization, users may be reluctant to authorize.) It's a good idea to only authorize apps that require user-given authorization. ):  _permissions =  [[nsarray arraywithobjects:@ "Get_user_info", @ "Get_simple_userinfo", @ "add_T ", Nil] retain];  five, call SDK Login 1. When you log on, call the authorize method of the Tencetnoauth object: [_tencentoauth authorize:_permissions Insafari: No]; 2. When the login is complete, the protocol method for login in Tencentsessiondelegate is called. Login successful:  @protocol tencentsessiondelegate <nsobject>-(void) tencentdidlogin{    _labeltitle.text = @ "Login Complete";        if (_tencentoauth.accesstoken && 0! = [_tencentoauth.accesstoken Length]) {   //  record login user's OpenID, token and expiration time         _labelaccesstoken.text = _ tencentoauth.accesstoken;   }    else    {        _ Labelaccesstoken.text = @ "Login unsuccessful did not get Accesstoken";   }} non-network error causes logon failure:  @protocol tencentsessiondelegate <nsobject>-(void) Tencentdidnotlogin: (BOOL) cancelled{if (cancelled) {_labeltitle.text = @ "user Cancel login";}else {_labeltitle.text = @ "Login Failed";The logon failure caused by a network error: @protocol tencentsessiondelegate <nsobject>-(void) tencentdidnotnetwork{[Email protected] "No network connection, please set up the network"; 3. Once the login is successful, access token and OpenID can be obtained. Accesstoken and OpenID are saved in the Tencentoauth object. Can be obtained directly through the corresponding property method. [_tencentoauth Accesstoken]; [_tencentoauth openId]; special note: 1. Because the logon is an asynchronous process, it is possible that the process of the entire login may not be completed properly due to user behavior, which is likely due to user behavior causing no login callbacks to be invoked after the login is complete. Developers need to take this into account when developing with the SDK, preventing the application from being stuck due to a callback that is waiting to be logged in synchronously, and it is recommended that the implementation be made an asynchronous process when logged in. 2. Acquired access token has a 3-month validity period and prompts the user to re-login authorization after expiration. 3. Third-party websites can store access token information for subsequent calls to Openapi to access and modify user information. If you need to save the authorization information, you need to save the login completed after the return of Accesstoken,openid and expirationdate three data, the next time you log in to the three data is set to the Tencentoauth object. Obtained: [_tencentoauth Accesstoken]; [_tencentoauth OpenId]; [_tencentoauth ExpirationDate]; set: [_tencentoauth Setaccesstoken:accesstoken]; [_tencentoauth Setopenid:openid]; [_tencentoauth setexpirationdate:expirationdate]; 4. It is recommended that after the user logs in, the GetUserInfo interface is called to get the user's avatar, nickname and display on the interface, which unifies the user experience.

IOS QQ login Fool type integration

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.