IOS Graphic Tutorial Complete three-party landing

Source: Internet
Author: User

Preface: First of all, you must understand that this integration of three things, are very simple, there may be pits, fill on the good, this article to micro-Bo for example, in fact, are the same. Step or complex or simple, habit is good.

1. Register as a developer on the Weibo open platform first http://open.weibo.com

2. Create an App

3. To improve the application information, it is important to note that bundle ID needs to be consistent with the application, while recording the Appkey project will use

4. In the application information-Advanced information

Consistent with the top---this code is followed by the use of the

5. Fill in the URL Types

6. Configure Info.plist to join the whitelist at the same time

 <array>  <string>sinaweibohd</string>  <string>sinaweibo</string>  <string>weibosdk</string>  <string>weibosdk2.5</string> </array>

7. Import the SDK.

7.1 Use cocoapods you can do this

pod "WeiboSDK", :git => "https://github.com/sinaweibosdk/weibo_ios_sdk.git"

7.2 or direct download drag into the project

8. Code

// AppDelegate中#import <WeiboSDK.h>#define WB_iOS_Key @""@interface AppDelegate ()<WeiboSDKDelegate>
   /**     *  1. 设置WeiboSDK的调试模式     *  2. 注册     */    [WeiboSDK enableDebugMode:YES];    [WeiboSDK registerApp:WB_iOS_Key];
#pragma mark-weibosdkdelegate-(void) Didreceiveweiborequest: (wbbaserequest *) request{}//write a callback based on your needs// This is the code provided by Weibo demo-(void) Didreceiveweiboresponse: (Wbbaseresponse *) response{if ([Response Iskindofclass:        Wbsendmessagetoweiboresponse.class]) {NSString *title = nslocalizedstring (@ "Send result", nil); NSString *message = [NSString stringwithformat:@ "%@:%d\\n%@:%@\\n%@:%@", nslocalizedstring (@ "Response status", nil), (int) Response.statuscode, nslocalizedstring (@ "Response userInfo data", nil), Response.userinfo, nslocalizedstring (@ "Original request UserInfo data        ", nil), Response.requestuserinfo];        wbsendmessagetoweiboresponse* sendmessagetoweiboresponse = (wbsendmessagetoweiboresponse*) response;        nsstring* Accesstoken = [Sendmessagetoweiboresponse.authresponse Accesstoken];        if (accesstoken) {self.wbtoken = Accesstoken;        } nsstring* userid = [sendmessagetoweiboresponse.authresponse userid];        if (userid) {self.wbcurrentuserid = userid; }    }    else if ([response IsKindOfClass:WBAuthorizeResponse.class]) {NSString *title = nslocalizedstring (@ "Authentication result",        NIL); NSString *message = [NSString stringwithformat:@ "%@:%d\\nresponse.userid:%@\\nresponse.accesstoken:%@\\n%@:%@\\n%@ :%@ ", nslocalizedstring (@" Response status ", nil), (int) response.statuscode,[(wbauthorizeresponse *) response UserID], [( Wbauthorizeresponse *) Response Accesstoken], nslocalizedstring (@ "Response userInfo data", nil), Response.userinfo,        Nslocalizedstring (@ "Original request userinfo data", nil), Response.requestuserinfo]; Uialertview *alert = [[Uialertview alloc] Initwithtitle:title Messa                                              Ge:message Delegate:nil        Cancelbuttontitle:nslocalizedstring (@ "OK", nil) otherbuttontitles:nil];        Self.wbtoken = [(Wbauthorizeresponse *) response Accesstoken]; Self.wbcurrentuserID = [(Wbauthorizeresponse *) response UserID];        Self.wbrefreshtoken = [(Wbauthorizeresponse *) response Refreshtoken];    [Alert show]; }}-(BOOL) Application: (UIApplication *) application OpenURL: (nsurl *) URL sourceapplication: (NSString *) sourceapplication annotation: (ID) annotation{return [Weibosdk handleopenurl:url delegate:self];} -(BOOL) Application: (UIApplication *) application Handleopenurl: (Nsurl *) url{return [weibosdk handleopenurl:url Delega Te:self];}

9. Write a login button to log in

- (void)loginClick{    [[[[UIApplication sharedApplication] delegate] window] makeKeyWindow];    WBAuthorizeRequest *request = [WBAuthorizeRequest request];    // 前面提到的    request.redirectURI = kRedirectURI;    request.scope = @"all";    request.userInfo = @{@"SSO_From": @"SendMessageToWeiboViewController",                         @"Other_Info_1": [NSNumber numberWithInt:123],                         @"Other_Info_2": @[@"obj1", @"obj2"],                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};    [WeiboSDK sendRequest:request];}

10. Complete the diagram

Status 0 stands for success. If the memory is not wrong basic will succeed. o.-

IOS Graphic Tutorial Complete three-party landing

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.