// // KDPAccountTool.m // KuDianProject // // Created by admin on 2019/7/9. // Copyright © 2019 KDP. All rights reserved. // #import "KDPAccountTool.h" #import //账号信息存储路径 #define CCAccountPath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.archive"] @implementation KDPAccountTool /** * 存储账号信息 * * @param account 账号模型 */ + (void)saveAccount:(KDPAccountModel *)account { //小米根据token注册别名 [MiPushSDK setAlias:account.token]; //将一个对象写入沙盒 需要用到一个NSKeyedArchiver 自定义对象的存储必须用这个 [NSKeyedArchiver archiveRootObject:account toFile:CCAccountPath]; } /** * 返回账号信息 * * @return 账号模型(如果账号过期,我们会返回nil) */ + (KDPAccountModel *)account { //加载模型 KDPAccountModel *account=[NSKeyedUnarchiver unarchiveObjectWithFile:CCAccountPath]; return account; } /** * 删除账号信息 * * @return 是否成功 */ + (BOOL)deleteAccount { //加载模型 KDPAccountModel *account=[NSKeyedUnarchiver unarchiveObjectWithFile:CCAccountPath]; [MiPushSDK unsetAlias:account.token]; [[NSUserDefaults standardUserDefaults]removeObjectForKey:UserPhone]; [[NSUserDefaults standardUserDefaults]synchronize]; return [[NSFileManager defaultManager] removeItemAtPath:CCAccountPath error:nil]; } /** 是否登录 @return 是否登录 */ + (BOOL)isLogin { KDPAccountModel *model = [self account]; if ([model.token isEqualToString:@""] || model.token == nil) { return NO; }else { return YES; } } @end