下面只展示项目开发中,本地序列化的示例代码:

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

iOS开发之功能模块--本地序列化的更多相关文章

  1. iOS开发之功能模块--高仿Boss直聘的常用语的开发

    首先上Boss直聘的功能界面截图,至于交互请读者现在Boss直聘去交互体验:     本人的公司项目要高仿Boss直聘的IM常用语的交互功能,居然花费了我前后17个小时完成,这回自己测试了很多遍,代码 ...

  2. IOS开发之功能模块--自定义导航控制器类常用自定义的代码

    前言:本文篇幅不多,但是涉及到的内容却是开发中常用的. 涉及的内容: 1.统一设置导航控制器子控制器的返回按钮. 2.因为修改了系统的返回按钮,所以还需要设置手势事件. 3.隐藏底部的工具条. 这里直 ...

  3. iOS开发之功能模块--Apns推送中的的json格式介绍

    在开发向苹果Apns推送消息服务功能,我们需要根据Apns接受的数据格式进行推送.下面接受我在进行apns推送时候总结的一点apns服务接受的Json数据格式 示例 1: 以下负载包含哦一个简单的 a ...

  4. iOS开发之功能模块--根据需求开发横向的子弹盒View

    这个需求是本人工作开发中后期需求要添加的新功能,本人模仿UITableView的代理和数据源方法进行了第一阶段的开发.第二阶段是添加丰富的动画. 这个功能需求描述:能上传添加五个待选头像,五个头像分别 ...

  5. iOS开发之功能模块--推送之坑问题解决

    不管想不想看我后面再开发中总结的经验,但是很值得推荐一位大神写的关于苹果推送,很多内容哦:http://www.cnblogs.com/qiqibo/category/408304.html 苹果开发 ...

  6. IOS开发之功能模块--给任意的UIView添加点击事件

    前言:好久没写博客,今天来一波.我在实际项目开发中,会遇到这样功能需求:我已经搭好了iOS的UI界面,但是很多界面的子View用了UIView,然后这些UIView中用了UILabel和UIImage ...

  7. iOS开发之功能模块--高仿Boss直聘的IM界面交互功能

    本人公司项目属于社交类,高仿Boss直聘早期的版本,现在Boss直聘界面风格,交互风格都不如Boss直聘以前版本的好看. 本人通过iPhone模拟器和本人真机对聊,将完成的交互功能通过Mac截屏模拟器 ...

  8. iOS开发之功能模块--计算高度Demo探究手稿

    本篇记录关于计算文本高度和Label高度的代码,以备后期再探究: 首先是YouXianMing老师的工具类别: NSString+LabelWidthAndHeight.h // // NSStrin ...

  9. iOS开发之功能模块--用runtime给UIView类别拓展PressMenu工具

    这是个很有用的列别工具类,在聊天对话框添加和QQ一样的"复制.粘贴.取消"等选项,而且使用起来很方便,只要找到聊天泡泡内部的某个View,比如Label或者背景冒泡的UIImage ...

随机推荐

  1. javascript之一切皆为对象2

    其实呢,“函数function”和“对象object”之间还有这么一句话:对象是通过函数来创建的,而函数却又是一种对象. 这个函数是一种对象,上节中“Javascript之一切皆为对象1”也清楚的阐述 ...

  2. Objective-C精选字符串处理方法

    无论是什么编程语言对字符串的操作是少不了的,对复杂的字符串的分析和操作我们可以用正则表达式来达到我们的目的.简单的字符串处理我们可以借助OC中NSString封装好的字符串处理方法,不过前提是你得了解 ...

  3. 确保 PHP 应用程序的安全

    开始之前在本教程中,您将学习如何在自己的 PHP Web 应用程序中添加安全性.本教程假设您至少有一年编写 PHP Web 应用程序的经验,所以这里不涉及 PHP 语言的基本知识(约定或语法).目标是 ...

  4. Repository 仓储,你的归宿究竟在哪?(一)-仓储的概念

    写在前面 写这篇博文的灵感来自<如何开始DDD(完)>,很感谢young.han兄这几天的坚持,陆陆续续写了几篇有关于领域驱动设计的博文,让园中再次刮了一阵"DDD探讨风&quo ...

  5. geotrellis使用(六)Scala并发(并行)编程

    本文主要讲解Scala的并发(并行)编程,那么为什么题目概称geotrellis使用(六)呢,主要因为本系列讲解如何使用Geotrellis,具体前几篇博文已经介绍过了.我觉得干任何一件事情基础很重要 ...

  6. Java 理论与实践: 正确使用 Volatile 变量--转

    原文地址:http://www.ibm.com/developerworks/cn/java/j-jtp06197.html Java 语言中的 volatile 变量可以被看作是一种 “程度较轻的  ...

  7. hibernate笔记--通过SchemaExport生成数据库表

    方法比较简单,项目中只需要两个java类(一个实体类,如User,一个工具类),两个配置文件(hibernate必须的两个配置文件hibernate.cfg.xml,与User.hbm.xml),即可 ...

  8. SQL Server基础之《视图的概述和基本操作》

     数据库中的视图是一个虚拟表.同真实的表一样,视图包含一系列带有名称的列和行数据,行和列数据用来自由定义视图和查询所引用的表,并且在引用视图时动态产生.本篇将通过一些实例来介绍视图的概念,视图的作用, ...

  9. seajs的使用--主要了解模块化

    一个使用sea.js的Demo sea.js可以解决命名问题,js文件间的依赖等. index.html内容如下: <!DOCTYPE html> <html xmlns=" ...

  10. Linux下查看版本号,查看存在的普通用户

    1. 查看版本号 uname -a ## 查看所有信息 uname --help ## 查看关于uname命令的帮助 2. 查看存在的普通用户 vim /etc/passwd ## 查看passwd文 ...