#import "ZHL_Model.h"
@interface LoginSucessModel : ZHL_Model
@property(strong, nonatomic)NSString *access_token;
@property(strong, nonatomic)NSString *token_type;
@property(strong, nonatomic)NSString *refresh_token;
@property(strong, nonatomic)NSString *expires_in;
@property(strong, nonatomic)NSString *scope;
+ (void)saveModel: (LoginSucessModel *)model;
+ (LoginSucessModel *)getModel;
+ (void)clearInfo;
@end
#define kLoginSucessModel @"LoginSucessModel"
#import "LoginSucessModel.h"
@implementation LoginSucessModel
static LoginSucessModel* _instance = nil;
+ (instancetype)model {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[super allocWithZone:NULL] init];
});
return _instance;
}
+ (id)allocWithZone: (struct _NSZone *)zone {
return [self model];
}
- (id)copyWithZone: (struct _NSZone *)zone {
return [[self class] model];
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super init]) {
self.access_token = [aDecoder decodeObjectForKey:@"access_token"];
self.token_type = [aDecoder decodeObjectForKey:@"token_type"];
self.refresh_token = [aDecoder decodeObjectForKey:@"refresh_token"];
self.expires_in = [aDecoder decodeObjectForKey:@"expires_in"];
self.scope = [aDecoder decodeObjectForKey:@"scope"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder; {
[aCoder encodeObject:self.access_token forKey:@"access_token"];
[aCoder encodeObject:self.token_type forKey:@"token_type"];
[aCoder encodeObject:self.refresh_token forKey:@"refresh_token"];
[aCoder encodeObject:self.expires_in forKey:@"expires_in"];
[aCoder encodeObject:self.scope forKey:@"scope"];
}
+ (void)saveModel: (LoginSucessModel *)model {
[[self model] saveModel:model];
}
- (void)saveModel: (LoginSucessModel *)model {
NSData *userData = [NSKeyedArchiver archivedDataWithRootObject: model];
iceUserDefaultsSetValueForKye(userData, kLoginSucessModel);
iceUserDefaultsSynchronize;
}
+ (LoginSucessModel *)getModel {
return [[self model] getModel];
}
- (LoginSucessModel *)getModel {
id data = iceUserDefaultsValueForKye(kLoginSucessModel);
if ([data isKindOfClass:[NSData class]]) {
LoginSucessModel *model = [NSKeyedUnarchiver unarchiveObjectWithData:data];
return model;
}
return nil;
}
+ (void)clearInfo {
[[self model] clearInfo];
}
- (void)clearInfo {
LoginSucessModel *emtyModel = [LoginSucessModel model];
emtyModel.access_token = nil;
emtyModel.token_type = nil;
emtyModel.refresh_token = nil;
emtyModel.expires_in = nil;
emtyModel.scope = nil;
[self saveModel:emtyModel];
}
@end