当前位置: 移动技术网 > IT编程>移动开发>IOS > 完整的iOS新浪微博分享功能开发

完整的iOS新浪微博分享功能开发

2019年07月24日  | 移动技术网IT编程  | 我要评论

蜡笔小小生国语下载,温州帅哥医生,厦门公交路线查询

本文实例为大家分享了android九宫格图片展示的具体代码,供大家参考,具体内容如下

做新浪分享 需先去http://open.weibo.com/apps注册开发者app 很简单!

第1步


第2步

3

设置你的应用的信息


找到自己的appkey


还需要设置自己的kappredirecturl测试可以随便写个!


开发部分在下面ios新浪微博分享(2)这部分:

开发需要下载官方的sdkhttp://open.weibo.com/wiki/sdk#ios_sdk


本人下载的版本


新建一个viewcontrroler==weiboviewcontroller

效果图


h文件

#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文件

#import "weiboviewcontroller.h"
#define kappkey    @"appkey"
#define kappsecret   @"appsecret"
#define kappredirecturl  @"重定向url"
@interface weiboviewcontroller ()



@end



@implementation weiboviewcontroller
@synthesize sharebutton = _sharebutton;
@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:@"accesstokenkey"];  
  _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(10, 10, 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];

}



//分享按钮响应方法

- (void) share:(uibutton*) sender

{
 sinaweibo *sinaweibo = [self sinaweibo];
 bool authvalid = sinaweibo.isauthvalid; 
 if (!authvalid)
 {
  [sinaweibo login];
 }
 else
 {
  nsstring *poststatustext = @"[哈哈]";  
  sinaweibo *sinaweibo = [self sinaweibo];
  //只发送汉字
//  [sinaweibo requestwithurl:@"statuses/update.json" params:[nsmutabledictionary dictionarywithobjectsandkeys:poststatustext,@"status", nil] httpmethod:@"post" delegate:self];
//图片和连接 和文字

  [sinaweibo requestwithurl:@"statuses/upload.json"

       params:[nsmutabledictionary dictionarywithobjectsandkeys:

         @"要发布的微博文本内容,超链接http://baidu.com", @"status",
         [uiimage imagenamed:@"icon.png"], @"pic", nil]

      httpmethod:@"post"
       delegate:self];
  
  [_shareview removefromsuperview];  
  [self.indicator startanimating];
 } 
}

//登陆成功后回调方法
- (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.refreshtoken, @"refresh_token", nil];
 [[nsuserdefaults standarduserdefaults] setobject:authdata forkey:@"sinaweiboauthdata"];

 [[nsuserdefaults standarduserdefaults] synchronize];

//可以在此选在授权成功后直接发送

}
//取消按钮回调方法
- (void) removeshare:(uibutton*) sender
{
 [_shareview removefromsuperview];

}

//发送按钮回调方法

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

}

//退出登陆回调方法
- (void) exitshare:(uibutton*) sender
{
 sinaweibo *sinaweibo = [self sinaweibo]; 
 [sinaweibo logout]; 
 [_shareview removefromsuperview]; 
 nslog(@"退出登陆");
}

//请求完成回调该方法
- (void)request:(sinaweiborequest *)request didfinishloadingwithresult:(id)result
{
 [self.indicator stopanimating]; 
 uialertview* alert = [[uialertview alloc] initwithtitle:@"发送成功" message:@"提示" delegate:self cancelbuttontitle:@"确定" otherbuttontitles: nil];
 [alert show];
 [alert release];
 nslog(@"发送成功");

}



//请求失败回调该方法
- (void)request:(sinaweiborequest *)request didfailwitherror:(nserror *)error

{
 [self.indicator stopanimating]; 
 uialertview* alert = [[uialertview alloc] initwithtitle:@"发送失败,请检测网络链接" message:@"提示" delegate:self cancelbuttontitle:@"确定" otherbuttontitles: nil];
 [alert show];
 [alert release];
 nslog(@"发送失败");

}

- (void)viewdidunload
{
 [super viewdidunload];
 // release any retained subviews of the main view.
}

- (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation
{
 return (interfaceorientation != uiinterfaceorientationportraitupsidedown);

}

@end

源码下载:

个人信息获得

@interface userinfoviewcontroller : uiviewcontroller<sinaweiborequestdelegate>//实现请求代理

bool authvalid = self.sina.isauthvalid;//判断是否授权了

 if (authvalid){

  [self.sina requestwithurl:@"users/show.json" params:[nsmutabledictionarydictionarywithobject:self.sina.userid forkey:@"uid"] httpmethod:@"get" delegate:self];

 }

//请求失败回调方法

- (void)request:(sinaweiborequest *)request didfailwitherror:(nserror *)error{

 if ([request.url hassuffix:@"users/show.json"]){

  [self.userinfodic release], self.userinfodic = nil;

 }

}



//请求成功回调方法

- (void)request:(sinaweiborequest *)request didfinishloadingwithresult:(id)result{

 if ([request.url hassuffix:@"users/show.json"]){

  [self.userinfodic release];

  self.userinfodic = [result retain];

  //nslog(@"用户信息字典:%@", self.userinfodic); 字典数据 返回字段下面

 }

 

}

返回字段说明

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

  • ios uicollectionview实现横向滚动

    现在使用卡片效果的app很多,之前公司让实现一种卡片效果,就写了一篇关于实现卡片的文章。文章最后附有demo实现上我选择了使用uicollectionview ... [阅读全文]
  • iOS UICollectionView实现横向滑动

    本文实例为大家分享了ios uicollectionview实现横向滑动的具体代码,供大家参考,具体内容如下uicollectionview的横向滚动,目前我使... [阅读全文]
  • iOS13适配深色模式(Dark Mode)的实现

    iOS13适配深色模式(Dark Mode)的实现

    好像大概也许是一年前, mac os系统发布了深色模式外观, 看着挺刺激, 时至今日用着也还挺爽的终于, 随着iphone11等新手机的发售, ios 13系统... [阅读全文]
  • ios 使用xcode11 新建项目工程的步骤详解

    ios 使用xcode11 新建项目工程的步骤详解

    xcode11新建项目工程,新增了scenedelegate这个类,转而将原appdelegate负责的对ui生命周期的处理担子接了过来。故此可以理解为:ios... [阅读全文]
  • iOS实现转盘效果

    本文实例为大家分享了ios实现转盘效果的具体代码,供大家参考,具体内容如下demo下载地址: ios转盘效果功能:实现了常用的ios转盘效果,轮盘抽奖效果的实现... [阅读全文]
  • iOS开发实现转盘功能

    本文实例为大家分享了ios实现转盘功能的具体代码,供大家参考,具体内容如下今天给同学们讲解一下一个转盘选号的功能,直接上代码直接看viewcontroller#... [阅读全文]
  • iOS实现轮盘动态效果

    本文实例为大家分享了ios实现轮盘动态效果的具体代码,供大家参考,具体内容如下一个常用的绘图,主要用来打分之类的动画,效果如下。主要是ios的绘图和动画,本来想... [阅读全文]
  • iOS实现九宫格连线手势解锁

    本文实例为大家分享了ios实现九宫格连线手势解锁的具体代码,供大家参考,具体内容如下demo下载地址:效果图:核心代码://// clockview.m// 手... [阅读全文]
  • iOS实现卡片堆叠效果

    本文实例为大家分享了ios实现卡片堆叠效果的具体代码,供大家参考,具体内容如下如图,这就是最终效果。去年安卓5.0发布的时候,当我看到安卓全新的material... [阅读全文]
  • iOS利用余弦函数实现卡片浏览工具

    iOS利用余弦函数实现卡片浏览工具

    本文实例为大家分享了ios利用余弦函数实现卡片浏览工具的具体代码,供大家参考,具体内容如下一、实现效果通过拖拽屏幕实现卡片移动,左右两侧的卡片随着拖动变小,中间... [阅读全文]
验证码:
移动技术网