CacheTool.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // CacheTool.m
  3. // Unity-iPhone
  4. //
  5. // Created by duowan123 on 2022/5/7.
  6. //
  7. #import "CacheTool.h"
  8. @implementation CacheTool
  9. #pragma mark ===============================================>>玩游戏过程中缓存 动作数据 和时间戳 数据存入plist
  10. +(void)cacheGameInfoInfo:(GameInfo*)gameInfo{
  11. // //总数
  12. // int total_step_count = game->getMotionCount(STEP_COUNT) - gameInfo.step;
  13. // int total_jump_count = game->getMotionCount(JUMP_COUNT) - gameInfo.jump;
  14. // int total_crouch_count = game->getMotionCount(DOWN_COUNT) - gameInfo.crouch;
  15. // int total_tick_count = game->getMotionCount(KICK_COUNT) - gameInfo.tick;
  16. // int total_paper_count = game->getMotionCount(PAPER_COUNT) - gameInfo.paper;
  17. // int total_scissors_count = game->getMotionCount(SCISSORS_COUNT) - gameInfo.scissors;
  18. // int total_rock_count = game->getMotionCount(ROCK_COUNT) - gameInfo.rock;
  19. // int total_trample_count = game->getMotionCount(ROCK_COUNT) - gameInfo.trample;
  20. //
  21. // //缓存pilst文件
  22. // NSMutableDictionary * motionCountObj = [NSMutableDictionary new];
  23. // [motionCountObj setObject:[NSNumber numberWithInt:total_step_count] forKey:@"step"];
  24. // [motionCountObj setObject:[NSNumber numberWithInt:total_jump_count] forKey:@"jump"];
  25. // [motionCountObj setObject:[NSNumber numberWithInt:total_crouch_count] forKey:@"crouch"];
  26. // [motionCountObj setObject:[NSNumber numberWithInt:total_tick_count] forKey:@"tick"];
  27. // [motionCountObj setObject:[NSNumber numberWithInt:total_paper_count] forKey:@"paper"];
  28. // [motionCountObj setObject:[NSNumber numberWithInt:total_scissors_count] forKey:@"scissors"];
  29. // [motionCountObj setObject:[NSNumber numberWithInt:total_rock_count] forKey:@"rock"];
  30. // [motionCountObj setObject:[NSNumber numberWithInt:0] forKey:@"trample"];
  31. //
  32. // NSMutableDictionary * movements = [NSMutableDictionary new];
  33. // [movements setObject:motionCountObj forKey:@"movements"];
  34. // //游戏总共经历的时长(秒数)
  35. // NSTimeInterval durationTime = [[NSDate date] timeIntervalSinceDate:gameInfo.firstTime];
  36. // [movements setObject:[NSNumber numberWithInt:durationTime] forKey:@"duration"];
  37. //
  38. // NSDictionary * dict = [NSDictionary dictionaryWithDictionary:movements];
  39. //
  40. // //归档缓存
  41. // [IOS_NSUSERDEFAULT setObject:dict forKey:IOSSDK_MOTIONCOUNT];
  42. // [IOS_NSUSERDEFAULT synchronize];
  43. //
  44. }
  45. //获取getUserInfo
  46. +(NSString*)getUserInfo{
  47. NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
  48. NSDictionary * user = jsonDict[@"user"];
  49. if ([user isKindOfClass:[NSNull class]] || user == nil || [user isEqual:[NSNull null]]){
  50. return @"";
  51. }else{
  52. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
  53. NSString * userJsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  54. return userJsonString;
  55. }
  56. }
  57. //获取token
  58. +(NSString*)getToken{
  59. NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
  60. NSString * token = [urlDict objectForKey:@"token"];
  61. if ([token isKindOfClass:[NSNull class]] || token == nil || [token isEqual:[NSNull null]]){
  62. // [PopupView showCusHUDA:@"获取token失败,请从趣动启动"];
  63. return @"";
  64. }else{
  65. return token;
  66. }
  67. }
  68. //获取缓存game_id
  69. +(NSString*)getGameId{
  70. NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
  71. NSString * game_id = [urlDict objectForKey:@"game_id"];
  72. if ([game_id isKindOfClass:[NSNull class]] || game_id == nil || [game_id isEqual:[NSNull null]]){
  73. // [PopupView showCusHUDA:@"获取id失败,请从趣动启动"];
  74. return @"";
  75. }else{
  76. return game_id;
  77. }
  78. }
  79. //获取缓存game_type
  80. +(NSString*)getGameType{
  81. NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
  82. NSString * game_type = [urlDict objectForKey:@"game_type"];
  83. if ([game_type isKindOfClass:[NSNull class]] || game_type == nil || [game_type isEqual:[NSNull null]]){
  84. // [PopupView showCusHUDA:@"获取type失败,请从趣动启动"];
  85. return @"";
  86. }else{
  87. return game_type;
  88. }
  89. }
  90. //获取缓存mac
  91. +(NSString*)getGameMac{
  92. NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
  93. NSString * mac = [urlDict objectForKey:@"mac"];
  94. if ([mac isKindOfClass:[NSNull class]] || mac == nil || [mac isEqual:[NSNull null]]){
  95. // [PopupView showCusHUDA:@"获取mac失败,请从趣动启动"];
  96. return @"";
  97. }else{
  98. return mac;
  99. }
  100. }
  101. //获取缓存邀请信息
  102. +(NSString*)getInviteUser{
  103. NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
  104. NSDictionary * invite = urlDict[@"invite"];
  105. if ([invite isKindOfClass:[NSNull class]] || invite == nil || [invite isEqual:[NSNull null]]){
  106. // [PopupView showCusHUDA:@"获取getInviteUser失败,请从趣动启动"];
  107. return @"";
  108. }else{
  109. //user字典 -> 字符串 -> Char
  110. NSDictionary * user = [invite objectForKey:@"user"];
  111. NSData * userData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
  112. NSString * userString = [[NSString alloc] initWithData:userData encoding:NSUTF8StringEncoding];
  113. return userString;
  114. }
  115. }
  116. +(NSString*)getInviteInfo{
  117. NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
  118. NSDictionary * invite = urlDict[@"invite"];
  119. if ([invite isKindOfClass:[NSNull class]] || invite == nil || [invite isEqual:[NSNull null]]){
  120. // [PopupView showCusHUDA:@"获取邀请信息失败,请从趣动启动"];
  121. return @"";
  122. }else{
  123. NSString * info = [invite objectForKey:@"info"];
  124. return info;
  125. }
  126. }
  127. //获取缓存vibrate
  128. +(NSString*)getGameVibrate{
  129. NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
  130. NSString * vibrate = [urlDict objectForKey:@"vibrate"];
  131. if ([vibrate isKindOfClass:[NSNull class]] || vibrate == nil || [vibrate isEqual:[NSNull null]]){
  132. // [PopupView showCusHUDA:@"获取mac失败,请从趣动启动"];
  133. return @"";
  134. }else{
  135. return vibrate;
  136. }
  137. }
  138. //获取缓存debug
  139. +(NSString*)getGameDebug{
  140. NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
  141. NSString * debug = [urlDict objectForKey:@"debug"];
  142. if ([debug isKindOfClass:[NSNull class]] || debug == nil || [debug isEqual:[NSNull null]]){
  143. // [PopupView showCusHUDA:@"获取mac失败,请从趣动启动"];
  144. return @"";
  145. }else{
  146. return debug;
  147. }
  148. }
  149. @end