最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

完整的iOS新浪微博分享功能開發(fā)

 更新時間:2020年07月29日 10:52:43   作者:young_for_your  
這篇文章主要為大家詳細(xì)介紹了較為完整的iOS新浪微博分享功能開發(fā)的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了iOS新浪微博分享功能的具體代碼,供大家參考,具體內(nèi)容如下

做新浪分享 需先去http://open.weibo.com/apps注冊開發(fā)者app 很簡單!

第1步

第2步

3

設(shè)置你的應(yīng)用的信息

找到自己的appkey

還需要設(shè)置自己的kAppRedirectURL測試可以隨便寫個!

開發(fā)部分在下面ios新浪微博分享(2)這部分:

開發(fā)需要下載官方的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];

}



//分享按鈕響應(yīng)方法

- (void) share:(UIButton*) sender

{
 SinaWeibo *sinaWeibo = [self sinaWeibo];
 BOOL authValid = sinaWeibo.isAuthValid; 
 if (!authValid)
 {
 [sinaWeibo logIn];
 }
 else
 {
 NSString *postStatusText = @"[哈哈]"; 
 SinaWeibo *sinaWeibo = [self sinaWeibo];
 //只發(fā)送漢字
// [sinaWeibo requestWithURL:@"statuses/update.json" params:[NSMutableDictionary dictionaryWithObjectsAndKeys:postStatusText,@"status", nil] httpMethod:@"POST" delegate:self];
//圖片和連接 和文字

 [sinaWeibo requestWithURL:@"statuses/upload.json"

    params:[NSMutableDictionary dictionaryWithObjectsAndKeys:

     @"要發(fā)布的微博文本內(nèi)容,超鏈接http://baidu.com", @"status",
     [UIImage imageNamed:@"Icon.png"], @"pic", nil]

   httpMethod:@"POST"
    delegate:self];
 
 [_shareView removeFromSuperview]; 
 [self.indicator startAnimating];
 } 
}

//登陸成功后回調(diào)方法
- (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];

//可以在此選在授權(quán)成功后直接發(fā)送

}
//取消按鈕回調(diào)方法
- (void) removeShare:(UIButton*) sender
{
 [_shareView removeFromSuperview];

}

//發(fā)送按鈕回調(diào)方法

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

}

//退出登陸回調(diào)方法
- (void) exitShare:(UIButton*) sender
{
 SinaWeibo *sinaWeibo = [self sinaWeibo]; 
 [sinaWeibo logOut]; 
 [_shareView removeFromSuperview]; 
 NSLog(@"退出登陸");
}

//請求完成回調(diào)該方法
- (void)request:(SinaWeiboRequest *)request didFinishLoadingWithResult:(id)result
{
 [self.indicator stopAnimating]; 
 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"發(fā)送成功" message:@"提示" delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];
 [alert show];
 [alert release];
 NSLog(@"發(fā)送成功");

}



//請求失敗回調(diào)該方法
- (void)request:(SinaWeiboRequest *)request didFailWithError:(NSError *)error

{
 [self.indicator stopAnimating]; 
 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"發(fā)送失敗,請檢測網(wǎng)絡(luò)鏈接" message:@"提示" delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];
 [alert show];
 [alert release];
 NSLog(@"發(fā)送失敗");

}

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}

@end

源碼下載:http://xiazai.jb51.net/201611/yuanma/SinaWeiboShare(jb51.net).rar

個人信息獲得

@interface UserInfoViewController : UIViewController<SinaWeiboRequestDelegate>//實現(xiàn)請求代理

BOOL authValid = self.sina.isAuthValid;//判斷是否授權(quán)了

 if (authValid){

 [self.sina requestWithURL:@"users/show.json" params:[NSMutableDictionarydictionaryWithObject:self.sina.userID forKey:@"uid"] httpMethod:@"GET" delegate:self];

 }

//請求失敗回調(diào)方法

- (void)request:(SinaWeiboRequest *)request didFailWithError:(NSError *)error{

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

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

 }

}



//請求成功回調(diào)方法

- (void)request:(SinaWeiboRequest *)request didFinishLoadingWithResult:(id)result{

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

 [self.userInfoDic release];

 self.userInfoDic = [result retain];

 //NSLog(@"用戶信息字典:%@", self.userInfoDic); 字典數(shù)據(jù) 返回字段下面

 }

 

}

返回字段說明

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS開發(fā)教程之扇形動畫的實現(xiàn)

    iOS開發(fā)教程之扇形動畫的實現(xiàn)

    實現(xiàn)扇形圖大家應(yīng)該都會的,但是扇形動畫大家都會實現(xiàn)嗎?下面這篇文章主要給大家介紹了關(guān)于iOS開發(fā)教程之扇形動畫實現(xiàn)的相關(guān)資料,文中介紹的非常詳細(xì),需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2017-06-06
  • iOS開發(fā)實現(xiàn)音頻播放功能

    iOS開發(fā)實現(xiàn)音頻播放功能

    本文給大家分享的是在IOS開發(fā)過程中實現(xiàn)音頻播放的功能,講解的十分細(xì)致,有需要的小伙伴可以參考下
    2016-03-03
  • Xcode8下iOS10常見報錯閃退,字體適配和編譯不過的問題及解決方案

    Xcode8下iOS10常見報錯閃退,字體適配和編譯不過的問題及解決方案

    蘋果推送了iOS10,好多朋友迅速即將系統(tǒng)升級了ios10,然后遇到好多問題。下面小編給針對遇到的問題給大家介紹解決方法,希望對大家有所幫助,感興趣的朋友可以參考下
    2016-09-09
  • iOS使用GCDSocketManager實現(xiàn)長連接的方法

    iOS使用GCDSocketManager實現(xiàn)長連接的方法

    下面想就為大家分享一篇iOS使用GCDSocketManager實現(xiàn)長連接的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • iOS?實現(xiàn)類似抖音滾動效果

    iOS?實現(xiàn)類似抖音滾動效果

    這篇文章主要介紹了iOS?實現(xiàn)類似抖音滾動效果,整體思路是我們將tableView 的contentinset設(shè)置為上面一個屏幕的高度,下面一個屏幕的高度,左右為0,這樣保證我們滾動過去的時候
    都是準(zhǔn)備好的內(nèi)容,需要的朋友可以參考下
    2024-06-06
  • iOS直播類APP開發(fā)流程解析

    iOS直播類APP開發(fā)流程解析

    這篇文章主要為大家詳細(xì)解析了iOS直播類APP開發(fā)流程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵

    iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵

    這篇文章主要介紹了iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵 的相關(guān)資料,需要的朋友可以參考下
    2016-08-08
  • Objective-C的緩存框架EGOCache在iOS App開發(fā)中的使用

    Objective-C的緩存框架EGOCache在iOS App開發(fā)中的使用

    這篇文章主要介紹了Objective-C的緩存框架EGOCache在iOS App開發(fā)中的使用,重點講解了EGOCache對緩存過期時間的檢測及處理,需要的朋友可以參考下
    2016-05-05
  • IOS開發(fā)中鍵盤輸入屏幕上移的解決方法

    IOS開發(fā)中鍵盤輸入屏幕上移的解決方法

    在IOS開法中經(jīng)常會遇到鍵盤遮擋屏幕的事情,經(jīng)常檔住下面的按鈕,下面小編給大家分享IOS開發(fā)中鍵盤輸入屏幕上移的解決方法,感興趣的朋友一起看看吧
    2016-10-10
  • iOS中讓多個cell上都出現(xiàn)倒計時的分析與實現(xiàn)

    iOS中讓多個cell上都出現(xiàn)倒計時的分析與實現(xiàn)

    這篇文章主要給大家介紹了在iOS中每個cell上都出現(xiàn)倒計時的分析與實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2017-07-07

最新評論

湘潭市| 双辽市| 大理市| 宽甸| 合水县| 黑山县| 西乌珠穆沁旗| 宁化县| 紫阳县| 手游| 浑源县| 咸阳市| 北京市| 全州县| 五台县| 汝阳县| 贵德县| 五指山市| 台州市| 逊克县| 简阳市| 安新县| 江西省| 集贤县| 高州市| 沭阳县| 墨玉县| 怀仁县| 牡丹江市| 应城市| 永泰县| 赣州市| 麦盖提县| 宁德市| 即墨市| 溆浦县| 卫辉市| 巨野县| 庐江县| 河池市| 嘉义县|