标签:
/** * 保存TOKEN * * @param token <#token description#> */ +(void)savaToken:(BZToken *) token { //2.沙河路径 NSLog(@"沙盒Path:%@",NSHomeDirectory()); //3.写入信息 //3.1 获取应用程序沙盒的Documents目录 NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *path=[paths objectAtIndex:0]; //3.2 得到完整的文件名 NSString *filename=[path stringByAppendingPathComponent:TOKEN_PLIST]; //3.3 需要保存的数据 value token.access_token key access_token NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:token.access_token,@"access_token",nil]; //3.4 写入数据 [dic writeToFile:filename atomically:YES]; } /** * 读取Token */ +(NSString *)readToken { //1 获取应用程序沙盒的Documents目录 NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *path=[paths objectAtIndex:0]; //2 完成路径 NSString *filename=[path stringByAppendingPathComponent:TOKEN_PLIST]; //获取路径 NSDictionary* dic = [NSDictionary dictionaryWithContentsOfFile:filename]; //3 返回数据 return [dic objectForKey:@"access_token"]; }
标签:
原文地址:http://my.oschina.net/u/1032974/blog/404089