IOS QQ login silly Integration

Source: Internet
Author: User
Tags openid

IOS QQ login silly Integration

1. To download the iOS SDK, go to the SDK download page and download the latest version of QQ to log on to the iOS SDK. 2. iOS SDK directory structure the iOS SDK package contains two files: 1. TencentOpenAPI. framework packages the header file definition and implementation of iOS SDK. 2. TencentOpenApi_iOS_Bundle.bundle packages the resource files required by the iOS SDK. 3. Add the iOS SDK file to the project. 1. Add TencentOpenAPI. framewZ Plugin in the iOS SDK? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> lost/r + 9sbS1vdOm08O/lost =" http://www.2cto.com/uploadfile/Collfiles/20141126/20141126084353137.png "alt =" \ "> 2. In the displayed dialog box, select "Create groups for any added folders" and remove "copy items into destination group's folder (if needed )", in Add to targets, select the target to be added to the SDK and click finish.
Then, the framework file of iOS SDK is added to the development project. 3. Add the system library file that the SDK depends on. They are "Security. framework, "libiconv. dylib "," SystemConfiguration. framework, "CoreGraphics. framework, libsqlite3.dylib, and CoreTelephony. framework and libstdc ++. dylib "," libz. dylib ". Open the project configuration file in Xcode and select the "summary" column. 4. Select "Linked Frameworks and Libraries" in "summary" and click the "+" icon. 5. directly select the default library file and click "Add" to Add "SystemConfiguration. framework 6. the system configuration. the framework already appears in "Linked Frameworks and Libraries. 7. Open the project configuration file in Xcode and select the "Build Phases" column. 8. Modify necessary engineering configuration attributes. In the project configuration, find the "Linking" configuration area in the "Build Settings" column and add the property value "-fobjc-arc" to the "Other Linker Flags" configuration item ". 4. Modify the necessary code 4.1 modify the project configuration file in XCode. Select your project settings and select the "TARGETS" column, in the "info" tab, add a new "URL scheme" and the new scheme = tencent + appid. If you are using XCode3 or a lower version, you must add it to the plist file. The appid we registered in the Demo is 222222. For example, when creating a project in Xcode 6.0, the Bundle display name attribute value may not be set separately by default. However, because the SDK needs to use the Bundle display name value, make sure that this attribute exists. If not, add it. 4.2 rewrite the handleOpenURL and openURL methods of AppDelegate 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 implement the TencentSessionDelegate protocol in the code For specific protocols, refer to TencentOAuth. Hin TencentOpenAPI. framework/Headers 4.4 to initialize the iOS sdk api data object TencentOAuth. (1) Create TencentOAuth and initialize its appid. The demo is 222222. Delegate is the object for implementing TencentSessionDelegate: _ tencentOAuth = [[TencentOAuth alloc] initWithAppId: @ "222222", andDelegate: self]; here delegate cannot be blank (2) initialize redirectURI (here you need to enter the domain name you entered when registering the APP. This parameter is optional by default. We recommend that you do not enter this parameter. The address used for registration in the demo is "www.qq.com"): _ tencentOAuth. redirectURI = @ "www.qq.com"; (3) set the list of APIs that the application requires user authorization. (It is recommended that the user be unwilling to authorize too many permissions. It is recommended that you only authorize the application .): _ Permissions = [[NSArray arrayWithObjects: @ "get_user_info", @ "get_simple_userinfo", @ "add_t", nil] retain]; 5. Call SDK to log on 1. at login, call the authorize method of the TencetnOAuth object: [_ tencentOAuth authorize: _ permissions inSafari: NO]; 2. after logon, the system calls the logon protocol method in TencentSessionDelegate. Logon successful: @ protocol TencentSessionDelegate
   
    
-(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 = @ "failed to log on. failed to get accesstoken";} non-network error cause logon Failure: @ protocol TencentSessionDelegate
    
     
-(Void) tencentDidNotLogin :( BOOL) canceled {if (canceled) {_ labelTitle. text = @ "";} else {_ labelTitle. text = @ "Logon Failed" ;}} logon failed due to network error: @ protocol TencentSessionDelegate
     
      
-(Void) tencentDidNotNetWork {_ labelTitle. text = @ "No network connection, set the network";} 3. After Successful Logon, you can obtain the access token and openid. The accessToken and openid are stored in the TencentOAuth object. You can use the corresponding property method to directly obtain it. [_ TencentOAuth accessToken]; [_ tencentOAuth openId]; Note: 1. because the logon process is asynchronous, the entire logon process may fail to be completed due to user behavior, that is, no logon callback is called after the logon is completed due to user behavior. Developers need to take this into account when using the SDK for development, to prevent the application from being stuck due to the synchronous waiting for login callback. It is recommended that this implementation be made into an asynchronous process during login. 2. The obtained access token has a validity period of three months. After expiration, the user is prompted to log on again for authorization. 3. Third-party websites can store access token information for later use when calling OpenAPI to access and modify user information. If you need to save the authorization information, you need to save the accessToken, openid, and expirationDate data returned after logon. When you log on next time, you can directly set the three data to the TencentOAuth object. Get: [_ tencentOAuth accessToken]; [_ tencentOAuth openId]; [_ tencentOAuth expirationDate]; Set: [_ tencentOAuth setAccessToken: accessToken]; [_ tencentOAuth setOpenId: openId] [_ tencentOAuth setExpirationDate: expirationDate]; 4. it is recommended that the application call the getUserInfo interface after a user logs on to obtain the profile picture and nickname of the user and display them on the interface to unify the user experience.
     
    
   

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.