新浪微博SDK2.4授权信息保存

新浪SDK中没有说明如何保存access_token到本地,每次打开应用都需要进行授权登陆。用文件把信息保存到本地,当再次打开应用的时候,先判断文件是否存在,如果存在,将access_token取出再进行数据的下载等操作。

1.当进行授权后系统会自动调用下面的方法,在此方法保存数据到本地。

- (void)didReceiveWeiboResponse:(WBBaseResponse *)response

{

//保存信息到本地

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *path = [paths objectAtIndex:0];

    NSString *filePath = [path stringByAppendingPathComponent:@"AuthData"];

    NSDictionary *authData = [NSDictionary dictionaryWithDictionary:response.userInfo];

    [authData writeToFile:filePath atomically:YES];

}

2.用户注销,即把文件移除掉,我用下面方法实现

-(void)logout:(UIBarButtonItem *)sender

{

    NSString *filePath = [self filePath];

    NSFileManager *manager = [NSFileManager defaultManager];

    [manager removeItemAtPath:filePath error:nil];

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值