SKPushMessage.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. //
  2. // SKPushMessage.m
  3. // Overseas Watch
  4. //
  5. // Created by 刘振兴 on 2024/1/8.
  6. // Copyright © 2024 BaH Cy. All rights reserved.
  7. //
  8. #import "SKPushMessage.h"
  9. #import "PopupView.h"
  10. #import "SKWebViewViewController.h"
  11. #import "SKWebSocket+queue.h"
  12. #import "VideoManager+socket.h"
  13. @implementation SKPushMessage
  14. + (void)didReceiveMessage:(NSString*)message {
  15. SocketModel* socketModel = [SocketModel mj_objectWithKeyValues:message];
  16. if (!socketModel)
  17. return;
  18. if (socketModel.msgType == 2) {
  19. NSDictionary* dic = socketModel.content;
  20. [[SKWebSocket share] sendAckId:[dic[@"ackId"] integerValue]];
  21. }
  22. switch (socketModel.msgType) {
  23. case -1: //服务器返回错误
  24. break;
  25. case 1: //Ping/Pong
  26. [[SKWebSocket share] removeQueueFromSocketModel:socketModel status:-1];
  27. break;
  28. case 20:
  29. case 21:
  30. case 22:
  31. case 23:
  32. case 24:
  33. //手表发的新语聊消息
  34. [self receiveChatMessages];
  35. break;
  36. case 31: { //定位点位变动消息,手表上报完成位置后会通过推送的方式下发位置到App
  37. SocketCoordinatesModel* model = [SocketCoordinatesModel mj_objectWithKeyValues:socketModel.content];
  38. [self receiveLocation:model];
  39. break;
  40. }
  41. case 30: //设备绑定状态变更消息,设备绑定状态变更的消息,一般由 App 发起绑定或解绑设备时出现
  42. case 32: //添加好友加过通知消息,两只手表互相通过好友 Code 加上好友后,相加的两人会收到这条消息
  43. case 33: //联系人变更通知消息,当小孩联系人数据变动时,这条消息会发送给手表设备和 App
  44. case 34: //闹钟变更通知消息,当小孩闹钟消息数据变动时,这条消息只会发送给手表设备
  45. case 35: //上课禁用变更通知消息,当小孩的上课禁用数据变动时,这条消息只会发送给手表设备
  46. case 36: //手表开机通知消息,手表开机时,这条消息会推中给 App
  47. case 37: //手表关机通知消息,手表关机时,这条消息会推中给 App
  48. case 38: //拒接陌生人变动通知消息,当小孩的拒接陌生人了开关数据变动时,这条消息只会发送给手表设备
  49. case 39: //消息中心变动通知消息,当监护人消息中心数据变动时,这条消息只会发送给 App
  50. [DataManager shared].isNewNotification = YES;
  51. for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
  52. if (object.delegate && [object.delegate respondsToSelector:@selector(onReceiveNewNotification:)]) {
  53. [object.delegate onReceiveNewNotification:YES];
  54. }
  55. }
  56. break;
  57. case 40: {//视频来电通知消息
  58. [[VideoManager shared] actionFromSocket:socketModel dial:1];
  59. break;
  60. }
  61. case 41: {//视频挂断通知消息
  62. [[VideoManager shared] actionFromSocket:socketModel dial:0];
  63. break;
  64. }
  65. case 50:
  66. //请求手表上报点位,App 通过 Ask 接口调用,发送通知消息到手表执行定位逻辑
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. + (void)postSocketStatusChange {
  73. for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
  74. if (object.delegate && [object.delegate respondsToSelector:@selector(onSocketStatusChange)]) {
  75. [object.delegate onSocketStatusChange];
  76. }
  77. }
  78. }
  79. + (void)postChatMessage:(SessionMessageModel*)model {
  80. for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
  81. if (object.delegate && [object.delegate respondsToSelector:@selector(onReceiveUpdateChat:)]) {
  82. [object.delegate onReceiveUpdateChat:model];
  83. }
  84. }
  85. }
  86. + (void)receiveChatMessages {
  87. NSInteger state = [UIApplication sharedApplication].applicationState;
  88. if (state == UIApplicationStateInactive) {
  89. //TODO:跳转到tabbar语聊页
  90. if ([[DataManager shared] getChildCount] > 0) {
  91. UIViewController* controller = [UIApplication sharedApplication].keyWindow.rootViewController;
  92. UITabBarController* tabbar = (UITabBarController*)controller;
  93. if (tabbar) {
  94. [tabbar setSelectedIndex:1];
  95. }
  96. } else {
  97. [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"TABBAR_SELECT_CHAT"];
  98. [[NSUserDefaults standardUserDefaults] synchronize];
  99. }
  100. } else {
  101. [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshChatCountFromAppDelegate" object:@{}];
  102. }
  103. for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
  104. if (object.delegate && [object.delegate respondsToSelector:@selector(onReceiveNewChat)]) {
  105. [object.delegate onReceiveNewChat];
  106. }
  107. }
  108. }
  109. + (void)receiveLocation:(SocketCoordinatesModel*)model {
  110. for (ChildModel* childModel in [DataManager shared].mChildList) {
  111. if ([childModel.cid isEqualToString:model.cid]) {
  112. childModel.lastLocation = model;
  113. childModel.lastLocation.latitude = model.lat;
  114. childModel.lastLocation.longitude = model.lon;
  115. }
  116. }
  117. for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
  118. if (object.delegate && [object.delegate respondsToSelector:@selector(onReceiveLocation:)]) {
  119. [object.delegate onReceiveLocation:model];
  120. }
  121. }
  122. }
  123. + (void)receiveWeather:(NSDictionary*)pushDic {
  124. //天气预警推送
  125. NSData *briefData = [pushDic[@"brief"] dataUsingEncoding:NSUTF8StringEncoding];
  126. NSMutableArray* array = [NSJSONSerialization JSONObjectWithData:briefData options:0 error:nil];
  127. NSMutableDictionary* data = [[NSMutableDictionary alloc] initWithDictionary:array[0]];
  128. NSMutableDictionary *dic = [NSMutableDictionary new];
  129. dic[@"WarnLevel"] = data[@"DefLevel"];
  130. dic[@"WarnType"] = data[@"DefCategory"];
  131. dic[@"WarnDetail"] = data[@"Content"];
  132. dic[@"WarnSummary"] = [NSString stringWithFormat:@"%@%@%@%@%@", data[@"Province"], @"气象局发布", data[@"Category"], data[@"Level"], NSLocalizedString(@"WWD.Warn", nil)];
  133. PopupView *view = [EUtil getBundleView:@"WeatherWarnView"];
  134. [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  135. view.mViewController = nil;
  136. view.mPushDic = dic;
  137. [[UIApplication sharedApplication].keyWindow addSubview:view];
  138. }
  139. + (void)receiveMagic:(NSDictionary*)pushDic {
  140. //魔法学院推送
  141. NSData *briefData = [pushDic[@"brief"] dataUsingEncoding:NSUTF8StringEncoding];
  142. NSMutableDictionary* data = [NSJSONSerialization JSONObjectWithData:briefData options:0 error:nil];
  143. ChildModel* mode = [[DataManager shared]getChild:pushDic[@"cid"]];
  144. NSMutableDictionary *dic = [NSMutableDictionary new];
  145. dic[@"MagicFinish"] = data[@"Total"];
  146. dic[@"MagicRight"] = data[@"Right"];
  147. NSString* typeKey = [NSString stringWithFormat:@"%@.%@",@"MA.Subject", data[@"Type"]];
  148. NSString* levelKey = [NSString stringWithFormat:@"%@.%@.%@",@"MA.Subject", data[@"Type"], data[@"Level"]];
  149. dic[@"MagicContent"] = [NSString stringWithFormat:@"%@%@%@%@%@", mode.name, NSLocalizedString(@"MA.Temp.1", nil), NSLocalizedString(typeKey, nil), NSLocalizedString(levelKey, nil), NSLocalizedString(@"MA.Temp.2", nil)];
  150. PopupView *view = [EUtil getBundleView:@"MagicReportView"];
  151. [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  152. view.mViewController = nil;
  153. view.mPushDic = dic;
  154. [[UIApplication sharedApplication].keyWindow addSubview:view];
  155. }
  156. + (void)receiveKidoMessage:(NSDictionary*)pushDic {
  157. //富文本推送
  158. BOOL isFinishLaunching = YES;
  159. if (isFinishLaunching) {
  160. //如果是刚启动,直接进入web
  161. NSString* url = pushDic[@"url"];
  162. if (url != nil && ![url isEqualToString:@""]) {
  163. NSString *title = pushDic[@"title"];
  164. UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
  165. SKWebViewViewController *webVc = [storyboard instantiateViewControllerWithIdentifier:@"WebViewVC"];
  166. webVc.title = title;
  167. webVc.urlToOpen = url;
  168. webVc.mIsShare = YES;
  169. webVc.mIsOpenApp = YES;
  170. webVc.mType = 16;
  171. webVc.mId = [pushDic[@"id"] integerValue];
  172. [EUtil pushViewController:webVc animated:YES];
  173. }
  174. } else {
  175. //如果App在运行中收到推送,弹框提示,再进入web
  176. [[NSNotificationCenter defaultCenter] postNotificationName:@"reciveKidoMessage" object:pushDic];
  177. }
  178. }
  179. + (void)receiveHighTemperature:(NSDictionary*)pushDic {
  180. //高温预警推送
  181. ChildModel* mode = [[DataManager shared]getChild:pushDic[@"cid"]];
  182. NSMutableDictionary *dic = [NSMutableDictionary new];
  183. dic[@"Content"] = [NSString stringWithFormat:@"%@%@", mode.name, NSLocalizedString(@"HT.Content", nil)];
  184. PopupView *view = [EUtil getBundleView:@"HighTemperatureView"];
  185. [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  186. view.mViewController = nil;
  187. view.mPushDic = dic;
  188. [[UIApplication sharedApplication].keyWindow addSubview:view];
  189. }
  190. + (void)testPush {
  191. int i = 1;
  192. if (i == 0) {
  193. //天气预警推送
  194. NSMutableDictionary *dic = [NSMutableDictionary new];
  195. dic[@"WarnLevel"] = @(3);
  196. dic[@"WarnType"] = @(2);
  197. dic[@"WarnDetail"] = @"hahhahhaa";
  198. dic[@"WarnSummary"] = @"hehehheheh";
  199. PopupView *view = [EUtil getBundleView:@"WeatherWarnView"];
  200. [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  201. view.mViewController = nil;
  202. view.mPushDic = dic;
  203. //view.layer.zPosition = INT8_MAX;
  204. [[UIApplication sharedApplication].keyWindow addSubview:view];
  205. }
  206. else if (i == 1) {
  207. NSMutableDictionary *dic = [NSMutableDictionary new];
  208. dic[@"MagicContent"] = @"测试数学";
  209. dic[@"MagicFinish"] = @"15";
  210. dic[@"MagicRight"] = @"12";
  211. PopupView *view = [EUtil getBundleView:@"MagicReportView"];
  212. [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  213. view.mViewController = nil;
  214. view.mPushDic = dic;
  215. //view.layer.zPosition = INT8_MAX;
  216. [[UIApplication sharedApplication].keyWindow addSubview:view];
  217. }
  218. }
  219. @end