跪求iOS開發的新浪微博授權登錄,要求源碼實現,不要第三方的,也不要靜態庫的,求大神給個Demo,本人小菜鳥一枚,剛工作不久,求大神關照,無以為報,只願好人一生平安!
QQ:903142826 郵箱[email protected]
1.首先你要有新浪開發者賬號,無非是到開放平台建立一個項目,然後把你的賬號添加進去,你創建的項目中有app key,app secret以及授權跳轉地址uri,還要在工程中導入新浪SDK
AppDelegate.h
#import "SinaWeibo.h"
#define kAppKey
#define kAppSecret
#define kAppRedirectURI
宏後面對應你的app key,app secret以及授權跳轉地址uri
AppDelegate..m
//初始化新浪微博對象
(void)_initSinaWeibo
{
_sinaweibo = [[SinaWeibo alloc] initWithAppKey:kAppKey appSecret:kAppSecret appRedirectURI:kAppRedirectURI 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"];
NSLog(@"讀取本地授權信息成功");
}
}
#pragma mark -SinaWeibo delegate
}
在你需要登錄的視圖控制器裡面
寫如下方法
//注銷賬號
//刪除新浪的認證信息
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"SinaWeiboAuthData"];
[[NSUserDefaults standardUserDefaults] synchronize];