Initial commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// GiGaUserDefault.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/15.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
|
||||
|
||||
@interface GiGaUserDefault : NSObject
|
||||
|
||||
+(void)saveUserId:(NSString *)userId;
|
||||
+(NSString *)getCurentUserId;
|
||||
+(void)removeUserId;
|
||||
+(BOOL)isUserLogin;
|
||||
/**
|
||||
保存用户表版本号
|
||||
*/
|
||||
+(void)saveDBVersion:(NSInteger)versionNum;
|
||||
|
||||
+(NSInteger)getOldVersion;
|
||||
|
||||
/**
|
||||
新手页(蒙版)
|
||||
@param showedGaurd 是否展示过 default NO
|
||||
*/
|
||||
+(void)saveUsergaurdflag:(BOOL)showedGaurd;
|
||||
+(BOOL)isShowedGaurd;
|
||||
|
||||
/**
|
||||
App 引导页
|
||||
@param showedGaurd 是否展示过 default NO
|
||||
*/
|
||||
+(void)saveAppGaurdflag:(BOOL)showedGaurd;
|
||||
+(BOOL)isShowedAppGaurd;
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// GiGaUserDefault.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/15.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaUserDefault.h"
|
||||
|
||||
NSString *const kUserManagerVerision = @"GiGAUserDBVeriosn";
|
||||
NSString *const GIGADEFAULTKEY_USERID = @"GiGaUserId";
|
||||
NSString *const kShowUserGuard = @"ShowUserGuard";
|
||||
NSString *const kShowAppGuard = @"ShowAppGuard";
|
||||
|
||||
@implementation GiGaUserDefault
|
||||
|
||||
+(void)saveUserId:(NSString *)userId{
|
||||
|
||||
UD_SET_KEY_VALUE(GIGADEFAULTKEY_USERID, userId);
|
||||
|
||||
}
|
||||
|
||||
+(NSString*)getCurentUserId{
|
||||
|
||||
NSString *userid = UD_GET_VALUE(GIGADEFAULTKEY_USERID);
|
||||
return userid;
|
||||
}
|
||||
|
||||
+(void)removeUserId{
|
||||
|
||||
UD_REMOVE_KEY(GIGADEFAULTKEY_USERID);
|
||||
}
|
||||
|
||||
+(BOOL)isUserLogin{
|
||||
|
||||
NSString *uid = UD_GET_VALUE(GIGADEFAULTKEY_USERID);
|
||||
return uid ? YES : NO;
|
||||
|
||||
}
|
||||
|
||||
+(void)saveDBVersion:(NSInteger)versionNum{
|
||||
|
||||
NSNumber *verNum = [NSNumber numberWithInteger:versionNum];
|
||||
UD_SET_KEY_VALUE(verNum.stringValue, kUserManagerVerision);
|
||||
|
||||
}
|
||||
|
||||
+ (NSInteger)getOldVersion{
|
||||
|
||||
return (NSInteger)UD_GET_VALUE(kUserManagerVerision);
|
||||
|
||||
}
|
||||
|
||||
+(void)saveUsergaurdflag:(BOOL)showedGaurd
|
||||
{
|
||||
[UD_STADARDUD setBool:showedGaurd forKey:kShowUserGuard];
|
||||
[UD_STADARDUD synchronize];
|
||||
|
||||
}
|
||||
|
||||
+(BOOL)isShowedGaurd
|
||||
{
|
||||
BOOL showedGaurd = [UD_STADARDUD boolForKey:kShowUserGuard];
|
||||
return showedGaurd;
|
||||
}
|
||||
|
||||
+(void)saveAppGaurdflag:(BOOL)showedGaurd;
|
||||
{
|
||||
[UD_STADARDUD setBool:showedGaurd forKey:kShowAppGuard];
|
||||
[UD_STADARDUD synchronize];
|
||||
}
|
||||
|
||||
+(BOOL)isShowedAppGaurd{
|
||||
BOOL showedGaurd = [UD_STADARDUD boolForKey:kShowAppGuard];
|
||||
return showedGaurd;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// GiGaUserManager.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/15.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "GiGaUser.h"
|
||||
@interface GiGaUserManager : NSObject
|
||||
|
||||
@property(nonatomic,strong) GiGaUser *user;
|
||||
|
||||
+(instancetype)shareUser;
|
||||
- (void)saveUser:(GiGaUser *)user;
|
||||
- (GiGaUser*)getCurrentUser;
|
||||
-(void)loginOut;
|
||||
|
||||
/**
|
||||
版本升级检测
|
||||
*/
|
||||
//-(void)detectionUserUpgrade;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// GiGaUserManager.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/15.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaUserManager.h"
|
||||
#import "YTKKeyValueStore.h"
|
||||
#import "GiGaUserDefault.h"
|
||||
|
||||
NSString *const GIGA_USER_TABLE = @"user_table";
|
||||
const static NSInteger GIGADB_USER_VER = 0;//当前数据库版本号
|
||||
|
||||
@interface GiGaUserManager()
|
||||
|
||||
@property (nonatomic,strong) YTKKeyValueStore *store;
|
||||
@property (nonatomic,strong) NSMutableArray *userArr;
|
||||
@property (nonatomic,copy) NSString *userTabId;
|
||||
|
||||
@end
|
||||
|
||||
@implementation GiGaUserManager
|
||||
|
||||
+ (instancetype)shareUser{
|
||||
static GiGaUserManager *userManager = nil;
|
||||
static dispatch_once_t once;
|
||||
dispatch_once(&once, ^{
|
||||
userManager = [[self alloc] init];
|
||||
|
||||
});
|
||||
|
||||
return userManager;
|
||||
}
|
||||
|
||||
-(instancetype)init{
|
||||
|
||||
self = [super init];
|
||||
if (self) {
|
||||
// 打开名为GiGa.db的数据库,如果该文件不存在,则创新一个新的。
|
||||
self.store = [[YTKKeyValueStore alloc] initDBWithName:@"GiGa.db"];
|
||||
[self creatTableByName:GIGA_USER_TABLE];
|
||||
_userArr = [NSMutableArray new];
|
||||
[self detectionUserUpgrade];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
//建表
|
||||
-(void)creatTableByName:(NSString *)tableName{
|
||||
[_store createTableWithName:tableName];
|
||||
}
|
||||
|
||||
- (void)saveUser:(GiGaUser *)user{
|
||||
|
||||
self.user = user;
|
||||
NSString *userTableId = [NSString stringWithFormat:@"%@",user.userId];
|
||||
self.userTabId = userTableId;
|
||||
|
||||
//暂定只保留一个用户
|
||||
[_userArr removeAllObjects];
|
||||
[_userArr addObject:user];
|
||||
[_store putObject:_userArr withId:userTableId intoTable:GIGA_USER_TABLE];
|
||||
[GiGaUserDefault saveUserId:userTableId];
|
||||
|
||||
}
|
||||
|
||||
//已登录
|
||||
-(GiGaUser *)getCurrentUser{
|
||||
|
||||
NSString *useriD = [GiGaUserDefault getCurentUserId];
|
||||
NSArray *usrA= [_store getObjectById:useriD fromTable:GIGA_USER_TABLE];
|
||||
if (usrA && usrA.count > 0) {
|
||||
self.user = usrA[0];
|
||||
}
|
||||
return self.user;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
-(void)loginOut{
|
||||
self.user = nil;
|
||||
[GiGaUserDefault removeUserId];
|
||||
|
||||
}
|
||||
|
||||
- (void)detectionUserUpgrade{
|
||||
|
||||
NSInteger oldVerion = [GiGaUserDefault getOldVersion];
|
||||
if (GIGADB_USER_VER <= oldVerion) {
|
||||
return;
|
||||
}
|
||||
[self upgradUserDBToNew];
|
||||
[GiGaUserDefault saveDBVersion:GIGADB_USER_VER];
|
||||
}
|
||||
|
||||
-(void)upgradUserDBToNew{
|
||||
|
||||
if (_userArr.count <= 0) {
|
||||
GILog(@"there is no user yet");
|
||||
return;
|
||||
}
|
||||
[_store putObject:_userArr withId:self.userTabId intoTable:GIGA_USER_TABLE];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user