下面只展示项目开发中,本地序列化的示例代码:
AuthenticationManager.h
#import <Foundation/Foundation.h>
#import "GrantViewController.h"
#import "MUUser.h"
#import "RoomEntity.h" #define kNotificationLogoutDone @"kNotification_logout_done"
#define kScoreChangeNotification @"kScoreChangeNotification" //金币变化
#define kExpriedTimeChangeNotification @"kExpriedTimeChangeNotification" //VIP时间变化
#define kRoomUpdateNotification @"kRoomUpdateNotification" //房间更新 @class Topic;
@class PlayableItem; @interface AuthenticationManager : NSObject + (MUUser *)authenticatedUser;
+ (BOOL)isAuthenticated;
+ (void)logout;
+ (void)updateUserDetail:(NSDictionary *)data;
+ (void)updateUserInfo:(MUUser *)user;
+ (void)updateUserAccessToken:(NSString *)token;
+ (void)addUnPublicTopicUserInfo:(NSMutableDictionary *)userInfo forKey:(NSString *)key;
+ (void)removeUnPublicTopicUserInfo:(NSString *)key;
+ (void)finishPresent;
+ (void)updateLatestTopicDate:(NSDate *)date;
+ (void)updateLatestActivityDate:(NSDate *)date;
+ (void)updateLatestSystemMessageDate:(NSDate *)date;
+ (void)updateLatestCheckFollowsDate:(NSDate *)date ;
+ (void)updateAutoPlaySetting:(NSInteger)setting;
+ (void)updateLastPlayTopic:(Topic *)topic;
+ (void)updateUserScore:(NSInteger)score;
+ (void)updateExpriedTime:(NSNumber *)time;
+ (void)updateRoom:(RoomEntity *)room;
+ (void)syncUserInfo; + (AuthenticationManager *)instance; @end
#import "NSMutableDictionary+Additions.h"
#import "XXUserManager.h" @interface AuthenticationManager() @property (nonatomic, strong) MusicEngine *dataEngine; @end @implementation AuthenticationManager + (void)logout{
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUserID];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUsername];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kPassword];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kSalt];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kEmail];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kAvatar];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kDisplayName];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kScore];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kToken];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kOpenID];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUserSocialAccount];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kDiangeType]; [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUserCover];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUserSign];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUserFollowings];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUserFollows]; [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUnPublicTopicUserInfo];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kPresentBefore];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kLatestTopicDate];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kLatestActivityDate];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kLatestSystemMessageDate];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kLatestCheckFollowsDate];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kAutoPlaySetting]; [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kGender];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kLocation];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kBirthday];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUserLastPlayTopic];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kExpriedTime]; [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kMoives];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kBooks];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kMusics];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kPets]; [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kCheckUploadPhotoTaskStatus]; [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kRoom]; [[NSUserDefaults standardUserDefaults] synchronize]; [[NSURLCache sharedURLCache] removeAllCachedResponses];
for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
} AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate.sinaWeiboOAuth logOut];
[appDelegate.tencentOAuth logout:nil];
} + (MUUser *)authenticatedUser {
if (![AuthenticationManager isAuthenticated]) {
DLog(@"用户未登录啊。");
return nil;
}
MUUser *user = [[MUUser alloc] init]; user.username = [[NSUserDefaults standardUserDefaults] objectForKey:kUsername];
user.password = [[NSUserDefaults standardUserDefaults] objectForKey:kPassword];
user.salt = [[NSUserDefaults standardUserDefaults] objectForKey:kSalt];
user.firstName = [[NSUserDefaults standardUserDefaults] objectForKey:kDisplayName];
user.email = [[NSUserDefaults standardUserDefaults] objectForKey:kEmail];
user.avatar = [[NSUserDefaults standardUserDefaults] objectForKey:kAvatar];
user.score = [[[NSUserDefaults standardUserDefaults] objectForKey:kScore] integerValue];
user.token = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
user.openID = [[NSUserDefaults standardUserDefaults] objectForKey:kOpenID];
user.userID = [[NSUserDefaults standardUserDefaults] integerForKey:kUserID]; user.cover = [[NSUserDefaults standardUserDefaults] objectForKey:kUserCover];
user.sign = [[NSUserDefaults standardUserDefaults] objectForKey:kUserSign];
user.followings = [[NSUserDefaults standardUserDefaults] integerForKey:kUserFollowings];
user.followers = [[NSUserDefaults standardUserDefaults] integerForKey:kUserFollows]; user.isPresentBefore = [[NSUserDefaults standardUserDefaults] boolForKey:kPresentBefore];
user.latestTopicDate = [[NSUserDefaults standardUserDefaults] objectForKey:kLatestTopicDate];
user.latestActivityDate = [[NSUserDefaults standardUserDefaults] objectForKey:kLatestActivityDate];
user.latestSystemMessageDate = [[NSUserDefaults standardUserDefaults] objectForKey:kLatestSystemMessageDate];
user.latestCheckFollowsDate = [[NSUserDefaults standardUserDefaults] objectForKey:kLatestCheckFollowsDate];
user.deadline = [[NSUserDefaults standardUserDefaults] objectForKey:kExpriedTime]; NSData *moviesData = [[NSUserDefaults standardUserDefaults] objectForKey:kMoives];
user.movies = [NSKeyedUnarchiver unarchiveObjectWithData: moviesData]; NSData *booksData = [[NSUserDefaults standardUserDefaults] objectForKey:kBooks];
user.books = [NSKeyedUnarchiver unarchiveObjectWithData: booksData]; NSData *musicsData = [[NSUserDefaults standardUserDefaults] objectForKey:kMusics];
user.musics = [NSKeyedUnarchiver unarchiveObjectWithData: musicsData]; NSData *petsData = [[NSUserDefaults standardUserDefaults] objectForKey:kPets];
user.pets = [NSKeyedUnarchiver unarchiveObjectWithData: petsData]; id autoPlaySetting = [[NSUserDefaults standardUserDefaults] objectForKey:kAutoPlaySetting];
if (autoPlaySetting)
user.autoPlaySetting = (enum AutoPlayType) [autoPlaySetting integerValue]; user.gender = [[NSUserDefaults standardUserDefaults] integerForKey:kGender];
user.location = [[NSUserDefaults standardUserDefaults] objectForKey:kLocation];
user.birthday = [[NSUserDefaults standardUserDefaults] objectForKey:kBirthday];
user.areaCode = [[NSUserDefaults standardUserDefaults] objectForKey:kAreaCode]; NSData *roomData = [[NSUserDefaults standardUserDefaults] objectForKey:kRoom];
user.room = [NSKeyedUnarchiver unarchiveObjectWithData:roomData]; NSDictionary *unPublicTopicUserInfo = [[NSUserDefaults standardUserDefaults] objectForKey:kUnPublicTopicUserInfo];
if (!unPublicTopicUserInfo)
user.unPublicTopicUserInfo = [NSMutableDictionary dictionary];
else
user.unPublicTopicUserInfo = [NSMutableDictionary dictionaryWithDictionary:unPublicTopicUserInfo]; NSData *myEncodedObject = [[NSUserDefaults standardUserDefaults] objectForKey:kUserSocialAccount];
user.social_accounts = [NSKeyedUnarchiver unarchiveObjectWithData: myEncodedObject];
if (user.social_accounts == nil) {
// 原来是有QQ帐号的呢。搞一个过去。
SocialAccount *account = [[SocialAccount alloc] init];
account.identity = [[NSUserDefaults standardUserDefaults] objectForKey:kOpenID];
account.type = SocialAccountQQ;
account.provider = @"qq";
account.isMaster = YES;
account.name = [[NSUserDefaults standardUserDefaults] objectForKey:kDisplayName];
account.accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
user.social_accounts = @[account];
} NSDictionary *topicDict = [[NSUserDefaults standardUserDefaults] objectForKey:kUserLastPlayTopic]; MUUser *owner = [[MUUser alloc] init];
owner.userID = [topicDict[@"userID"] integerValue];
owner.username = topicDict[@"userName"];
owner.firstName = topicDict[@"firstName"]; Topic *topic = [[Topic alloc] init];
topic.topicID = [topicDict[@"topicID"] integerValue];
topic.name = topicDict[@"topicName"];
topic.cover = topicDict[@"topicCover"];
topic.owner = owner;
user.lastPlayTopic = topic; return user;
} + (BOOL)isAuthenticated { return [XXUserManager isAuth]; NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:kUsername];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:kPassword];
return username && password ? YES : NO;
} + (void)updateUserDetail:(NSDictionary *)data{
[[NSUserDefaults standardUserDefaults] setObject:data[@"u"] forKey:kUsername];
[[NSUserDefaults standardUserDefaults] setObject:data[@"m"] forKey:kEmail];
[[NSUserDefaults standardUserDefaults] setObject:data[@"p"] forKey:kPassword];
[[NSUserDefaults standardUserDefaults] setObject:data[@"s"] forKey:kSalt];
[[NSUserDefaults standardUserDefaults] setObject:data[@"d"] forKey:kDisplayName];
[[NSUserDefaults standardUserDefaults] setObject:data[@"t"] forKey:kToken];
[[NSUserDefaults standardUserDefaults] setObject:data[@"i"] forKey:kOpenID];
[[NSUserDefaults standardUserDefaults] setObject:data[@"h"] forKey:kAvatar];
[[NSUserDefaults standardUserDefaults] setInteger:[data[@"id"] integerValue] forKey:kUserID];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)updateUserInfo:(MUUser *)user{
[[NSUserDefaults standardUserDefaults] setObject:user.username forKey:kUsername];
[[NSUserDefaults standardUserDefaults] setObject:user.email forKey:kEmail];
[[NSUserDefaults standardUserDefaults] setObject:user.firstName forKey:kDisplayName];
[[NSUserDefaults standardUserDefaults] setObject:user.avatar forKey:kAvatar];
[[NSUserDefaults standardUserDefaults] setInteger:user.userID forKey:kUserID];
[[NSUserDefaults standardUserDefaults] setObject:user.cover forKey:kUserCover];
[[NSUserDefaults standardUserDefaults] setObject:user.sign forKey:kUserSign];
[[NSUserDefaults standardUserDefaults] setInteger:user.followers forKey:kUserFollows];
[[NSUserDefaults standardUserDefaults] setInteger:user.followings forKey:kUserFollowings];
[[NSUserDefaults standardUserDefaults] setInteger:user.score forKey:kScore];
[[NSUserDefaults standardUserDefaults] setInteger:user.gender forKey:kGender];
[[NSUserDefaults standardUserDefaults] setObject:user.location forKey:kLocation];
[[NSUserDefaults standardUserDefaults] setObject:user.birthday forKey:kBirthday];
[[NSUserDefaults standardUserDefaults] setObject:user.deadline forKey:kExpriedTime]; NSData *moviesData = [NSKeyedArchiver archivedDataWithRootObject:user.movies];
[[NSUserDefaults standardUserDefaults] setObject:moviesData forKey:kMoives]; NSData *booksData = [NSKeyedArchiver archivedDataWithRootObject:user.books];
[[NSUserDefaults standardUserDefaults] setObject:booksData forKey:kBooks]; NSData *musicData = [NSKeyedArchiver archivedDataWithRootObject:user.musics];
[[NSUserDefaults standardUserDefaults] setObject:musicData forKey:kMusics]; NSData *petsData = [NSKeyedArchiver archivedDataWithRootObject:user.pets];
[[NSUserDefaults standardUserDefaults] setObject:petsData forKey:kPets]; NSData *roomData = [NSKeyedArchiver archivedDataWithRootObject:user.room];
[[NSUserDefaults standardUserDefaults] setObject:roomData forKey:kRoom]; [[NSUserDefaults standardUserDefaults] setObject:user.areaCode forKey:kAreaCode]; NSData *archiveCarPriceData = [NSKeyedArchiver archivedDataWithRootObject:user.social_accounts];
[[NSUserDefaults standardUserDefaults] setObject:archiveCarPriceData forKey:kUserSocialAccount]; if (user.password && ![user.password isEqualToString:@""]) {
if ([[NSUserDefaults standardUserDefaults] objectForKey:kPassword] == nil) {
[[NSUserDefaults standardUserDefaults] setObject:user.password forKey:kPassword];
}
} if (user.salt && ![user.salt isEqualToString:@""]) {
if ([[NSUserDefaults standardUserDefaults] objectForKey:kSalt] == nil) {
[[NSUserDefaults standardUserDefaults] setObject:user.salt forKey:kSalt];
}
}
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)updateUserAccessToken:(NSString *)token {
[[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)addUnPublicTopicUserInfo:(NSMutableDictionary *)userInfo forKey:(NSString *)key {
NSDictionary *topicUserInfo = [[NSUserDefaults standardUserDefaults] objectForKey:kUnPublicTopicUserInfo];
NSMutableDictionary *unPublicTopicUserInfo;
if (!topicUserInfo)
unPublicTopicUserInfo = [NSMutableDictionary dictionary];
else
unPublicTopicUserInfo = [NSMutableDictionary dictionaryWithDictionary:topicUserInfo];
unPublicTopicUserInfo[key] = userInfo;
[[NSUserDefaults standardUserDefaults] setObject:unPublicTopicUserInfo forKey:kUnPublicTopicUserInfo];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)removeUnPublicTopicUserInfo:(NSString *)key {
NSDictionary *topicUserInfo = [[NSUserDefaults standardUserDefaults] objectForKey:kUnPublicTopicUserInfo];
if (!topicUserInfo)
return; NSMutableDictionary *unPublicTopicUserInfo = [NSMutableDictionary dictionaryWithDictionary:topicUserInfo];
[unPublicTopicUserInfo removeObjectForKey:key];
[[NSUserDefaults standardUserDefaults] setObject:unPublicTopicUserInfo forKey:kUnPublicTopicUserInfo];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)finishPresent {
[[NSUserDefaults standardUserDefaults] setObject:@YES forKey:kPresentBefore];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)updateLatestTopicDate:(NSDate *)date {
[[NSUserDefaults standardUserDefaults] setObject:date forKey:kLatestTopicDate];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)updateLatestActivityDate:(NSDate *)date {
[[NSUserDefaults standardUserDefaults] setObject:date forKey:kLatestActivityDate];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)updateLatestSystemMessageDate:(NSDate *)date {
[[NSUserDefaults standardUserDefaults] setObject:date forKey:kLatestSystemMessageDate];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)updateLatestCheckFollowsDate:(NSDate *)date {
[[NSUserDefaults standardUserDefaults] setObject:date forKey:kLatestCheckFollowsDate];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)updateAutoPlaySetting:(NSInteger)setting {
[[NSUserDefaults standardUserDefaults] setObject:@(setting) forKey:kAutoPlaySetting];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)updateLastPlayTopic:(Topic *)topic {
NIDPRINT(@"更新最后播放的节目信息: %@", topic);
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict safeSetObject:@(topic.topicID) forKey:@"topicID"];
[dict safeSetObject:topic.name forKey:@"topicName"];
[dict safeSetObject:topic.cover forKey:@"topicCover"];
[dict safeSetObject:@(topic.owner.userID) forKey:@"userID"];
[dict safeSetObject:topic.owner.firstName forKey:@"firstName"];
[dict safeSetObject:topic.owner.username forKey:@"userName"];
[[NSUserDefaults standardUserDefaults] setObject:dict forKey:kUserLastPlayTopic];
[[NSUserDefaults standardUserDefaults] synchronize];
} + (void)updateUserScore:(NSInteger)score {
[[NSUserDefaults standardUserDefaults] setObject:@(score) forKey:kScore];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:kScoreChangeNotification object:self userInfo:nil];
} + (void)updateExpriedTime:(NSNumber *)time {
[[NSUserDefaults standardUserDefaults] setObject:time forKey:kExpriedTime];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:kExpriedTimeChangeNotification object:[self authenticatedUser] userInfo:nil];
} + (void)updateRoom:(RoomEntity *)room {
NSData *roomData = [NSKeyedArchiver archivedDataWithRootObject:room];
[[NSUserDefaults standardUserDefaults] setObject:roomData forKey:kRoom];
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomUpdateNotification object:[self authenticatedUser] userInfo:nil];
} + (void)syncUserInfo {
MUUser *oldUser = [AuthenticationManager authenticatedUser];
if (!oldUser)
return; @weakify(self)
[[self instance].dataEngine loadUserByUserId:oldUser.userID success:^(MUUser *userEntity, NSDictionary *userInfo) {
NIDPRINT(@"旧金币:%ld 新金币:%ld", (long)oldUser.score,(long)userEntity.score);
[AuthenticationManager updateUserInfo:userEntity];
@strongify(self)
if (oldUser.score != userEntity.score) {
[[NSNotificationCenter defaultCenter] postNotificationName:kScoreChangeNotification object:self userInfo:nil];
}
if (oldUser.deadline.integerValue != userEntity.deadline.integerValue) {
[[NSNotificationCenter defaultCenter] postNotificationName:kExpriedTimeChangeNotification object:self userInfo:nil];
}
} failure:^(id result, NSDictionary *userInfo) { }];
} + (AuthenticationManager *)instance {
static AuthenticationManager *_instance = nil; @synchronized (self) {
if (_instance == nil) {
_instance = [[self alloc] init];
}
} return _instance;
} - (MusicEngine *)dataEngine {
if (!_dataEngine) {
_dataEngine = [[MusicEngine alloc] init];
}
return _dataEngine;
} @end
第二个示例:XXUserManager
#import <Foundation/Foundation.h>
#import "XXUserModel.h" @interface XXUserManager : NSObject + (BOOL)isAuth; + (XXUserModel *)authUser; + (void)updateAuthUser:(XXUserModel *)authUser; + (void)updateUserInfo:(XXUserModel *)user; + (void)logout; @end
#import "XXUserManager.h" #define kXXUserId @"xxUserid"
#define kXXUserName @"xxUsername"
#define kXXSalt @"xxSalt"
#define kXXSecret @"xxSecret"
#define kXXMobile @"xxMobile"
#define kXXNickName @"xxNickname"
#define kXXAvatar @"xxAvatar"
#define kXXSex @"xxSex"
#define kXXBirthday @"xxBirthday"
#define kXXLocation @"xxLocation"
#define kXXSign @"xxSign"
#define kXXFollowers @"xxFollowers"
#define kXXFollowings @"xxFollowings"
#define kXXEarning @"xxEarning"
#define kXXScores @"xxScores"
#define kXXTimUsersig @"xxTimusersig"
#define kXXValue @"kXXValue" @implementation XXUserManager + (XXUserModel *)authUser { XXUserModel *autnUser = [[XXUserModel alloc] init]; autnUser.userId = [[NSUserDefaults standardUserDefaults] objectForKey:kXXUserId];
autnUser.username = [[NSUserDefaults standardUserDefaults] objectForKey:kXXUserName];
autnUser.salt = [[NSUserDefaults standardUserDefaults] objectForKey:kXXSalt];
autnUser.secret = [[NSUserDefaults standardUserDefaults] objectForKey:kXXSecret];
autnUser.mobile = [[NSUserDefaults standardUserDefaults] objectForKey:kXXMobile];
autnUser.nickname = [[NSUserDefaults standardUserDefaults] objectForKey:kXXNickName];
autnUser.avatar = [[NSUserDefaults standardUserDefaults] objectForKey:kXXAvatar];
autnUser.sex = [[NSUserDefaults standardUserDefaults] integerForKey:kXXSex];
autnUser.birthday = [[NSUserDefaults standardUserDefaults] objectForKey:kXXBirthday];
autnUser.location = [[NSUserDefaults standardUserDefaults] objectForKey:kXXLocation];
autnUser.sign = [[NSUserDefaults standardUserDefaults] objectForKey:kXXSign];
autnUser.followers = [[NSUserDefaults standardUserDefaults] integerForKey:kXXFollowers];
autnUser.followings = [[NSUserDefaults standardUserDefaults] in8tegerForKey:kXXFollowings];
autnUser.earning = [[NSUserDefaults standardUserDefaults] integerForKey:kXXEarning];
autnUser.value = [[NSUserDefaults standardUserDefaults] integerForKey:kXXValue]; NSData *scoresData = [[NSUserDefaults standardUserDefaults] objectForKey:kXXScores];
autnUser.scores = [NSKeyedUnarchiver unarchiveObjectWithData:scoresData]; autnUser.timUsersig = [[NSUserDefaults standardUserDefaults] objectForKey:kXXTimUsersig]; return autnUser;
} + (void)updateAuthUser:(XXUserModel *)authUser { [[NSUserDefaults standardUserDefaults] setObject:authUser.userId forKey:kXXUserId];
[[NSUserDefaults standardUserDefaults] setObject:authUser.username forKey:kXXUserName];
[[NSUserDefaults standardUserDefaults] setObject:authUser.salt forKey:kXXSalt];
[[NSUserDefaults standardUserDefaults] setObject:authUser.secret forKey:kXXSecret];
[[NSUserDefaults standardUserDefaults] setObject:authUser.mobile forKey:kXXMobile];
[[NSUserDefaults standardUserDefaults] setObject:authUser.nickname forKey:kXXNickName];
[[NSUserDefaults standardUserDefaults] setObject:authUser.avatar forKey:kXXAvatar];
[[NSUserDefaults standardUserDefaults] setInteger:authUser.sex forKey:kXXSex];
[[NSUserDefaults standardUserDefaults] setObject:authUser.birthday forKey:kXXBirthday];
[[NSUserDefaults standardUserDefaults] setObject:authUser.location forKey:kXXLocation];
[[NSUserDefaults standardUserDefaults] setObject:authUser.sign forKey:kXXSign];
[[NSUserDefaults standardUserDefaults] setInteger:authUser.followers forKey:kXXFollowers];
[[NSUserDefaults standardUserDefaults] setInteger:authUser.followings forKey:kXXFollowings];
[[NSUserDefaults standardUserDefaults] setInteger:authUser.earning forKey:kXXEarning]; NSData *scoresData = [NSKeyedArchiver archivedDataWithRootObject:authUser.scores];
[[NSUserDefaults standardUserDefaults] setObject:scoresData forKey:kXXScores]; [[NSUserDefaults standardUserDefaults] setObject:authUser.timUsersig forKey:kXXTimUsersig];
[[NSUserDefaults standardUserDefaults] synchronize]; } + (void)updateUserInfo:(XXUserModel *)user { if (user.nickname) {
[[NSUserDefaults standardUserDefaults] setObject:user.nickname forKey:kXXNickName];
}
if (user.avatar) {
[[NSUserDefaults standardUserDefaults] setObject:user.avatar forKey:kXXAvatar];
} if (user.sex) {
[[NSUserDefaults standardUserDefaults] setInteger:user.sex forKey:kXXSex];
} if (user.birthday) {
[[NSUserDefaults standardUserDefaults] setObject:user.birthday forKey:kXXBirthday];
} if (user.location) {
[[NSUserDefaults standardUserDefaults] setObject:user.location forKey:kXXLocation];
} if (user.sign) {
[[NSUserDefaults standardUserDefaults] setObject:user.sign forKey:kXXSign];
}
[[NSUserDefaults standardUserDefaults] synchronize]; } + (void)logout{ [[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXUserId];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXUserName];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXSalt];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXSecret];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXMobile];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXNickName];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXAvatar];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXSex];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXBirthday];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXLocation];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXSign];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXFollowers];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXFollowings];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXEarning];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXScores];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXTimUsersig];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kXXValue];
[[NSUserDefaults standardUserDefaults] synchronize]; } + (BOOL)isAuth {
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:kXXUserName];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:kXXSecret];
return username && password ? YES : NO;
} @end