123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- //
- // SKPushMessage.m
- // Overseas Watch
- //
- // Created by 刘振兴 on 2024/1/8.
- // Copyright © 2024 BaH Cy. All rights reserved.
- //
- #import "SKPushMessage.h"
- #import "PopupView.h"
- #import "SKWebViewViewController.h"
- #import "SKWebSocket+queue.h"
- @implementation SKPushMessage
- + (void)didReceiveMessage:(NSString*)message {
- SocketModel* socketModel = [SocketModel mj_objectWithKeyValues:message];
- if (!socketModel)
- return;
-
- if (socketModel.msgType == 2) {
- NSDictionary* dic = socketModel.content;
- [[SKWebSocket share] sendAckId:[dic[@"ackId"] integerValue]];
- }
-
- switch (socketModel.msgType) {
- case -1: //服务器返回错误
- break;
-
- case 1: //Ping/Pong
- [[SKWebSocket share] removeQueueFromSocketModel:socketModel status:-1];
- break;
-
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- //手表发的新语聊消息
- [self receiveChatMessages];
- break;
-
- case 31: { //定位点位变动消息,手表上报完成位置后会通过推送的方式下发位置到App
- SocketCoordinatesModel* model = [SocketCoordinatesModel mj_objectWithKeyValues:socketModel.content];
- [self receiveLocation:model];
- break;
- }
-
- case 30: //设备绑定状态变更消息,设备绑定状态变更的消息,一般由 App 发起绑定或解绑设备时出现
- case 32: //添加好友加过通知消息,两只手表互相通过好友 Code 加上好友后,相加的两人会收到这条消息
- case 33: //联系人变更通知消息,当小孩联系人数据变动时,这条消息会发送给手表设备和 App
- case 34: //闹钟变更通知消息,当小孩闹钟消息数据变动时,这条消息只会发送给手表设备
- case 35: //上课禁用变更通知消息,当小孩的上课禁用数据变动时,这条消息只会发送给手表设备
- case 36: //手表开机通知消息,手表开机时,这条消息会推中给 App
- case 37: //手表关机通知消息,手表关机时,这条消息会推中给 App
- case 38: //拒接陌生人变动通知消息,当小孩的拒接陌生人了开关数据变动时,这条消息只会发送给手表设备
- case 39: //消息中心变动通知消息,当监护人消息中心数据变动时,这条消息只会发送给 App
- [DataManager shared].isNewNotification = YES;
- for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
- if (object.delegate && [object.delegate respondsToSelector:@selector(onReceiveNewNotification:)]) {
- [object.delegate onReceiveNewNotification:YES];
- }
- }
- break;
-
- case 40: {//视频来电通知消息
- [[VideoManager shared] actionFromSocket:socketModel dial:1];
- break;
- }
- case 41: {//视频挂断通知消息
- [[VideoManager shared] actionFromSocket:socketModel dial:0];
- break;
- }
-
- case 50:
- //请求手表上报点位,App 通过 Ask 接口调用,发送通知消息到手表执行定位逻辑
- break;
- default:
- break;
- }
- }
- + (void)postSocketStatusChange {
- for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
- if (object.delegate && [object.delegate respondsToSelector:@selector(onSocketStatusChange)]) {
- [object.delegate onSocketStatusChange];
- }
- }
- }
- + (void)postChatMessage:(SessionMessageModel*)model {
- for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
- if (object.delegate && [object.delegate respondsToSelector:@selector(onReceiveUpdateChat:)]) {
- [object.delegate onReceiveUpdateChat:model];
- }
- }
- }
- + (void)receiveChatMessages {
- NSInteger state = [UIApplication sharedApplication].applicationState;
- if (state == UIApplicationStateInactive) {
- //TODO:跳转到tabbar语聊页
- if ([[DataManager shared] getChildCount] > 0) {
- UIViewController* controller = [UIApplication sharedApplication].keyWindow.rootViewController;
- UITabBarController* tabbar = (UITabBarController*)controller;
- if (tabbar) {
- [tabbar setSelectedIndex:1];
- }
- } else {
- [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"TABBAR_SELECT_CHAT"];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
- } else {
- [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshChatCountFromAppDelegate" object:@{}];
- }
-
- for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
- if (object.delegate && [object.delegate respondsToSelector:@selector(onReceiveNewChat)]) {
- [object.delegate onReceiveNewChat];
- }
- }
- }
- + (void)receiveLocation:(SocketCoordinatesModel*)model {
- for (ChildModel* childModel in [DataManager shared].mChildList) {
- if ([childModel.cid isEqualToString:model.cid]) {
- childModel.lastLocation = model;
- childModel.lastLocation.latitude = model.lat;
- childModel.lastLocation.longitude = model.lon;
- }
- }
-
- for (MutableDelegateObject* object in [DataManager shared].delegateObjects) {
- if (object.delegate && [object.delegate respondsToSelector:@selector(onReceiveLocation:)]) {
- [object.delegate onReceiveLocation:model];
- }
- }
- }
- + (void)receiveWeather:(NSDictionary*)pushDic {
- //天气预警推送
- NSData *briefData = [pushDic[@"brief"] dataUsingEncoding:NSUTF8StringEncoding];
- NSMutableArray* array = [NSJSONSerialization JSONObjectWithData:briefData options:0 error:nil];
- NSMutableDictionary* data = [[NSMutableDictionary alloc] initWithDictionary:array[0]];
-
- NSMutableDictionary *dic = [NSMutableDictionary new];
- dic[@"WarnLevel"] = data[@"DefLevel"];
- dic[@"WarnType"] = data[@"DefCategory"];
- dic[@"WarnDetail"] = data[@"Content"];
- dic[@"WarnSummary"] = [NSString stringWithFormat:@"%@%@%@%@%@", data[@"Province"], @"气象局发布", data[@"Category"], data[@"Level"], NSLocalizedString(@"WWD.Warn", nil)];
-
- PopupView *view = [EUtil getBundleView:@"WeatherWarnView"];
- [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- view.mViewController = nil;
- view.mPushDic = dic;
- [[UIApplication sharedApplication].keyWindow addSubview:view];
- }
- + (void)receiveMagic:(NSDictionary*)pushDic {
- //魔法学院推送
- NSData *briefData = [pushDic[@"brief"] dataUsingEncoding:NSUTF8StringEncoding];
- NSMutableDictionary* data = [NSJSONSerialization JSONObjectWithData:briefData options:0 error:nil];
-
- ChildModel* mode = [[DataManager shared]getChild:pushDic[@"cid"]];
-
- NSMutableDictionary *dic = [NSMutableDictionary new];
- dic[@"MagicFinish"] = data[@"Total"];
- dic[@"MagicRight"] = data[@"Right"];
- NSString* typeKey = [NSString stringWithFormat:@"%@.%@",@"MA.Subject", data[@"Type"]];
- NSString* levelKey = [NSString stringWithFormat:@"%@.%@.%@",@"MA.Subject", data[@"Type"], data[@"Level"]];
- dic[@"MagicContent"] = [NSString stringWithFormat:@"%@%@%@%@%@", mode.name, NSLocalizedString(@"MA.Temp.1", nil), NSLocalizedString(typeKey, nil), NSLocalizedString(levelKey, nil), NSLocalizedString(@"MA.Temp.2", nil)];
-
- PopupView *view = [EUtil getBundleView:@"MagicReportView"];
- [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- view.mViewController = nil;
- view.mPushDic = dic;
- [[UIApplication sharedApplication].keyWindow addSubview:view];
- }
- + (void)receiveKidoMessage:(NSDictionary*)pushDic {
- //富文本推送
- BOOL isFinishLaunching = YES;
- if (isFinishLaunching) {
- //如果是刚启动,直接进入web
- NSString* url = pushDic[@"url"];
- if (url != nil && ![url isEqualToString:@""]) {
-
- NSString *title = pushDic[@"title"];
- UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
- SKWebViewViewController *webVc = [storyboard instantiateViewControllerWithIdentifier:@"WebViewVC"];
- webVc.title = title;
- webVc.urlToOpen = url;
- webVc.mIsShare = YES;
- webVc.mIsOpenApp = YES;
- webVc.mType = 16;
- webVc.mId = [pushDic[@"id"] integerValue];
- [EUtil pushViewController:webVc animated:YES];
- }
- } else {
- //如果App在运行中收到推送,弹框提示,再进入web
- [[NSNotificationCenter defaultCenter] postNotificationName:@"reciveKidoMessage" object:pushDic];
- }
- }
- + (void)receiveHighTemperature:(NSDictionary*)pushDic {
- //高温预警推送
- ChildModel* mode = [[DataManager shared]getChild:pushDic[@"cid"]];
-
- NSMutableDictionary *dic = [NSMutableDictionary new];
- dic[@"Content"] = [NSString stringWithFormat:@"%@%@", mode.name, NSLocalizedString(@"HT.Content", nil)];
-
- PopupView *view = [EUtil getBundleView:@"HighTemperatureView"];
- [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- view.mViewController = nil;
- view.mPushDic = dic;
- [[UIApplication sharedApplication].keyWindow addSubview:view];
- }
- + (void)testPush {
-
- int i = 1;
- if (i == 0) {
- //天气预警推送
- NSMutableDictionary *dic = [NSMutableDictionary new];
- dic[@"WarnLevel"] = @(3);
- dic[@"WarnType"] = @(2);
- dic[@"WarnDetail"] = @"hahhahhaa";
- dic[@"WarnSummary"] = @"hehehheheh";
-
- PopupView *view = [EUtil getBundleView:@"WeatherWarnView"];
- [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- view.mViewController = nil;
- view.mPushDic = dic;
- //view.layer.zPosition = INT8_MAX;
- [[UIApplication sharedApplication].keyWindow addSubview:view];
- }
- else if (i == 1) {
-
- NSMutableDictionary *dic = [NSMutableDictionary new];
- dic[@"MagicContent"] = @"测试数学";
- dic[@"MagicFinish"] = @"15";
- dic[@"MagicRight"] = @"12";
-
- PopupView *view = [EUtil getBundleView:@"MagicReportView"];
- [view setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- view.mViewController = nil;
- view.mPushDic = dic;
- //view.layer.zPosition = INT8_MAX;
- [[UIApplication sharedApplication].keyWindow addSubview:view];
- }
- }
- @end
|