酷店

KDPAccountTool.m 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // KDPAccountTool.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/9.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPAccountTool.h"
  9. #import <MiPushSDK.h>
  10. //账号信息存储路径
  11. #define CCAccountPath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.archive"]
  12. @implementation KDPAccountTool
  13. /**
  14. * 存储账号信息
  15. *
  16. * @param account 账号模型
  17. */
  18. + (void)saveAccount:(KDPAccountModel *)account
  19. {
  20. //小米根据token注册别名
  21. [MiPushSDK setAlias:account.token];
  22. //将一个对象写入沙盒 需要用到一个NSKeyedArchiver 自定义对象的存储必须用这个
  23. [NSKeyedArchiver archiveRootObject:account toFile:CCAccountPath];
  24. }
  25. /**
  26. * 返回账号信息
  27. *
  28. * @return 账号模型(如果账号过期,我们会返回nil)
  29. */
  30. + (KDPAccountModel *)account
  31. {
  32. //加载模型
  33. KDPAccountModel *account=[NSKeyedUnarchiver unarchiveObjectWithFile:CCAccountPath];
  34. return account;
  35. }
  36. /**
  37. * 删除账号信息
  38. *
  39. * @return 是否成功
  40. */
  41. + (BOOL)deleteAccount
  42. {
  43. //加载模型
  44. KDPAccountModel *account=[NSKeyedUnarchiver unarchiveObjectWithFile:CCAccountPath];
  45. [MiPushSDK unsetAlias:account.token];
  46. [[NSUserDefaults standardUserDefaults]removeObjectForKey:UserPhone];
  47. [[NSUserDefaults standardUserDefaults]synchronize];
  48. return [[NSFileManager defaultManager] removeItemAtPath:CCAccountPath error:nil];
  49. }
  50. /**
  51. 是否登录
  52. @return 是否登录
  53. */
  54. + (BOOL)isLogin {
  55. KDPAccountModel *model = [self account];
  56. if ([model.token isEqualToString:@""] || model.token == nil) {
  57. return NO;
  58. }else {
  59. return YES;
  60. }
  61. }
  62. @end