This example for you to share the Android nine Sudoku picture display of the specific code for your reference, the specific content as follows
Sina share to do first to Http://open.weibo.com/apps registered developer app is very simple!
1th Step
2nd Step
3
Set up information for your application
Find your own appkey.
Also need to set up their own Kappredirecturl test can write a random!
Development section below iOS Sina Weibo share (2) This part:
Development needs to download the official SDKHTTP://OPEN.WEIBO.COM/WIKI/SDK#IOS_SDK
I download the version
Create a new Viewcontrroler==weiboviewcontroller
Effect chart
H file
#import
#import "sinaweb/sinaweibo/sinaweibo.h"
#import "sinaweb/sinaweibo/sinaweiborequest.h"
@ Interface weiboviewcontroller:uiviewcontroller<</span>sinaweibodelegate,sinaweiborequestdelegate>
{
UIButton *_sharebutton;
Uitextview *_textview;
UIView *_shareview;
Uiactivityindicatorview *_indicator;}
@property (Strong, nonatomic) UIButton *sharebutton;
@property (Strong, nonatomic) Uitextview *textview;
@property (Strong, nonatomic) UIView *shareview;
@property (Strong, nonatomic) Uiactivityindicatorview *indicator;
@property (readonly, nonatomic) Sinaweibo *sinaweibo;
-(void) AddButton;
-(void) Addshareview;
-(void) Share: (uibutton*) sender;
-(void) Removeshare: (uibutton*) sender;
-(void) Sendshare: (uibutton*) sender;
-(void) Exitshare: (uibutton*) sender;
@end
M file
#import "WeiBoViewController.h" #define Kappkey @ "Appkey" #define Kappsecret @ "Appsecret" #define KAPPREDIRECTURL @ The redirect URL @interface weiboviewcontroller () @end @implementation weiboviewcontroller @synthesize Sharebutton = _share
Button;
@synthesize TextView = _textview;
@synthesize Shareview = _shareview;
@synthesize indicator = _indicator;
@synthesize Sinaweibo = _sinaweibo;
-(sinaweibo*) Sinaweibo {_sinaweibo.delegate=self;
return _sinaweibo;
}-(void) viewdidload {[Super viewdidload]; _indicator = [[Uiactivityindicatorview alloc] Initwithactivityindicatorstyle:
Uiactivityindicatorviewstylewhitelarge];
[_indicator setframe:cgrectmake (0, 0, 50, 50)];
_indicator.center = Self.view.center;
[Self.view Addsubview:_indicator]; _sinaweibo = [[Sinaweibo alloc] Initwithappkey:kappkey appsecret:kappsecret appredirecturi:kappredirecturl
Anddelegate:self];
Nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults]; Nsdictionary *sinaweiboinfo = [DEfaults objectforkey:@ "Sinaweiboauthdata"]; if ([Sinaweiboinfo objectforkey:@ "Accesstokenkey"] && [sinaweiboinfo objectforkey:@ "Expirationdatekey"] && [Sinaweiboinfo objectforkey:@ "Useridkey"]) {_sinaweibo.accesstoken = [sinaweiboinfo objectforkey:@] Access
Tokenkey "];
_sinaweibo.expirationdate = [Sinaweiboinfo objectforkey:@ "Expirationdatekey"];
_sinaweibo.userid = [Sinaweiboinfo objectforkey:@ "Useridkey"];
} [self AddButton];
}-(void) AddButton {_sharebutton = [UIButton buttonwithtype:uibuttontyperoundedrect];
Uiimage*butimg=[uiimage imagenamed:@ "Button_background@2x.png"];
Uiimage*logobutimg=[uiimage imagenamed:@ "Logo@2x.png"];
[Self.sharebutton Setframe:cgrectmake (Ten, Butimg.size.width, Butimg.size.height)];
[Self.sharebutton setbackgroundimage:butimg Forstate:uicontrolstatenormal];
[Self.sharebutton setimage:logobutimg Forstate:uicontrolstatenormal]; [Self.sharebutton addtarget:self Action: @selector (share:) Forcontrolevents:uiconTroleventtouchupinside];
[Self.view AddSubview:self.shareButton];
//Share button response Method-(void) Share: (uibutton*) Sender {Sinaweibo *sinaweibo = [self Sinaweibo];
BOOL authvalid = sinaweibo.isauthvalid;
if (!authvalid) {[Sinaweibo logIn];
else {NSString *poststatustext = @ "[haha]";
Sinaweibo *sinaweibo = [self Sinaweibo]; Send only Chinese characters//[Sinaweibo requestwithurl:@ "Statuses/update.json" params:[nsmutabledictionary
dictionarywithobjectsandkeys:poststatustext,@ "status", Nil] httpmethod:@ "POST" delegate:self]; Pictures and connections and text [Sinaweibo requestwithurl:@ "Statuses/upload.json" Params:[nsmutabledictionary dictionarywithobjects
Andkeys: @ "Tweet text content to post, Hyperlink http://baidu.com", @ "status", [UIImage imagenamed:@ "Icon.png"], @ "pic", Nil]
httpmethod:@ "POST" delegate:self];
[_shareview Removefromsuperview];
[Self.indicator startanimating]; }///Login Successful callback Method-(void) Sinaweibodidlogin: (Sinaweibo *) Sinaweibo {NSLog (@ "%@--%@--%@--%@", SinaweiBo.accesstoken,sinaweibo.expirationdate, Sinaweibo.userid,sinaweibo.refreshtoken);
Nsdictionary *authdata = [nsdictionary DictionaryWithObjectsAndKeys:sinaweibo.accessToken, @ "Accesstokenkey", Sinaweibo.expirationdate, @ "Expirationdatekey", Sinaweibo.userid, @ "Useridkey", Sinaweibo.refreshtoke
N, @ "Refresh_token", nil];
[[Nsuserdefaults Standarduserdefaults] setobject:authdata forkey:@ "Sinaweiboauthdata"];
[[Nsuserdefaults standarduserdefaults] synchronize];
This option can be sent directly after the authorization succeeds//Cancel button callback method-(void) Removeshare: (uibutton*) Sender {[_shareview removefromsuperview];
//Send button callback method-(void) Sendshare: (uibutton*) Sender {NSString *poststatustext = Self.textView.text;
Sinaweibo *sinaweibo = [self Sinaweibo]; [Sinaweibo requestwithurl:@ "Statuses/updates.json" params:[nsmutabledictionary Dictionarywithobjectsandkeys:
poststatustext,@ "status", Nil] httpmethod:@ "POST" delegate:self];
[_shareview Removefromsuperview]; [Self.indicator StartanimatinG];
//Exit Login callback Method-(void) Exitshare: (uibutton*) Sender {Sinaweibo *sinaweibo = [self Sinaweibo];
[Sinaweibo LogOut];
[_shareview Removefromsuperview];
NSLog (@ "Exit login"); //Request Complete Callback this method-(void) Request: (Sinaweiborequest *) Request Didfinishloadingwithresult: (ID) result {[Self.indicator
Stopanimating]; uialertview* alert = [[Uialertview alloc] initwithtitle:@ "Send Success" message:@ "Prompt" delegate:self cancelbuttontitle:@ "OK"
Otherbuttontitles:nil];
[Alert show];
[Alert release];
NSLog (@ "send success"); //Request failed callback this method-(void) Request: (Sinaweiborequest *) Request Didfailwitherror: (Nserror *) error {[Self.indicator Stopani
Mating]; uialertview* alert = [[Uialertview alloc] initwithtitle:@ send failed, check the network link "message:@ prompt" Delegate:self cancelbuttontitle:
@ "determine" otherbuttontitles:nil];
[Alert show];
[Alert release];
NSLog (@ "send failed");
}-(void) viewdidunload {[Super viewdidunload];
Release any retained subviews of the main view. }-(BOOL) Shouldautorotatetointerfaceorientation: (UIINTERFACEorientation) interfaceorientation {return (interfaceorientation!= uiinterfaceorientationportraitupsidedown);
} @end
SOURCE Download: Http://xiazai.jb51.net/201611/yuanma/SinaWeiboShare (jb51.net). rar
Personal Information access
@interface userinfoviewcontroller:uiviewcontroller<sinaweiborequestdelegate>//Implementation Request Proxy
BOOL authvalid = self.sina.isauthvalid;//whether to authorize the
if (authvalid) {
[Self.sina requestwithurl:@ ' Users/show.json ' params:[ NSMutableDictionarydictionaryWithObject:self.sina.userID forkey:@ "UID"] httpmethod:@ "get" delegate:self];
}
Request failed callback method
-(void) Request: (Sinaweiborequest *) Request Didfailwitherror: (Nserror *) error{
if ([Request.url hassuffix:@ "Users/show.json"]) {
[self.userinfodic release], self.userinfodic = nil;
}
}
Request successful callback method
-(void) Request: (Sinaweiborequest *) Request Didfinishloadingwithresult: (ID) result{
if ([ Request.url hassuffix:@ "Users/show.json"]) {
[self.userinfodic release];
Self.userinfodic = [result retain];
NSLog (@ "User Information dictionary:%@", self.userinfodic); Dictionary data return field below
}
}
return field Description
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.