zoukankan      html  css  js  c++  java
  • DeviceDelegateHelper.m

    //

    //  DeviceDelegateHelper.m

    //  ECSDKDemo_OC

    //

    //  Created by jiazy on 14/12/5.

    //  Copyright (c) 2014 ronglian. All rights reserved.

    //

     

    #import "DeviceDelegateHelper.h"

    #import "EmojiConvertor.h"

    #define LOG_OPEN 0

     

     

    @interface DeviceDelegateHelper()

    @property(atomic, assign) NSUInteger offlineCount;

    @end

     

    @implementation DeviceDelegateHelper{

        SystemSoundID receiveSound;

        NSUserDefaults *userDefaul;

        NSMutableArray *fllowupDoc;

        NSMutableArray *PublicArr;

        

        Dlpontlerexple *dleaexp;

        NSMutableArray *distinctionMutarr;

     

        

        NSMutableArray *REqumutarr;

        NSMutableArray *PulistChatMutarr;

        

        

        int devieInt;

    }

     

    +(DeviceDelegateHelper*)sharedInstance{

        static DeviceDelegateHelper *devicedelegatehelper;

        static dispatch_once_t devicedelegatehelperonce;

        dispatch_once(&devicedelegatehelperonce, ^{

            devicedelegatehelper = [[DeviceDelegateHelper alloc] init];

        });

        return devicedelegatehelper;

    }

     

    -(instancetype)init{

        if (self = [super init]) {

            devieInt=0;

            [self xiaoxiguilingdef];

            NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"receive_msg"

                                                                  ofType:@"caf"];

            NSURL *soundURL = [NSURL fileURLWithPath:soundPath];

            OSStatus err = AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL,

                                                            &receiveSound);

            userDefaul = [NSUserDefaults standardUserDefaults];

            dleaexp = [Dlpontlerexple shareIndence];

            if (err != kAudioServicesNoError)

                MCLog(@"Could not load %@, error code: %d", soundURL, (int)err);

        }

        return self;

    }

    - (void)dealloc

    {

        AudioServicesDisposeSystemSoundID(receiveSound);

    }

    #if LOG_OPEN

    -(void)onLogInfo:(NSString*)log {

        MCLog(@"ECDeviceSDK LOG:%@",log);

    }

    #endif

     

     

    - (void)xiaoxiguilingdef

    {

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(xiaoxinectStateChanged:) name:@"XIAOXIFUILING" object:nil];

     

     

    }

    -(void)xiaoxinectStateChanged:(NSNotification *)notification

    {

     

        devieInt=0;

     

     

    }

    -(void)playRecMsgSound:(NSString*)sessionId{

    //    MCLog(@"gzz0302接收消息判断");

    //后台切前台接收消息判断

        devieInt=2;

        if (self.preDate==nil) {

            self.preDate = [NSDate date];

        }

        if (self.isB2F && self.preDate != nil && [self.preDate timeIntervalSinceNow]>-1) {

            self.preDate = [NSDate date];

            return;

        }

        

        self.isB2F = NO;

        

    //是否在会话里接收消息

        BOOL isChat = NO;

        if (self.sessionId.length>0 && sessionId.length>0 && [self.sessionId isEqualToString:sessionId]) {

            isChat = YES;

        }

    //    MCLog(@"是否在会话里接收消息-----%@--",isChat);

        if (![[IMMsgDBAccess sharedInstance] isNoticeOfGroupId:sessionId]) {

            return;

        }

        

        

     

        

    //查看设置

        if ([DemoGlobalClass sharedInstance].isMessageSound && !isChat) {

            //播放声音

            AudioServicesPlaySystemSound(receiveSound);

        }

        

        if ([DemoGlobalClass sharedInstance].isMessageShake){

            //震动

            AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);

        }

    }

     

    /**

     @brief 网络改变后调用的代理方法

     @param status 网络状态值

     */

    - (void)onReachbilityChanged:(ECNetworkType)status{

        [DemoGlobalClass sharedInstance].netType = status;

        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onNetworkChanged object:@(status)];

    }

     

    #if 0

     

    /**

     @brief 连接状态接口

     @discussion 监听与服务器的连接状态 V4.0版本接口

     @param error 连接的状态

     */

    -(void)onConnected:(ECError *)error{

        MCLog(@" ========== onConnected errorcode=%d ============", (int)error.errorCode);

        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onConnected object:error];

    }

     

    #else

     

    /**

     @brief 连接状态接口  gzz0720  一直保持链接状态 如果没有网络的情况下

     @discussion 监听与服务器的连接状态 V5.0版本接口

     @param state 连接的状态

     @param error 错误原因值

     */

    -(void)onConnectState:(ECConnectState)state failed:(ECError*)error {

    //    MCLog(@"--gzz0720error--%@------720----errorCode---%ld",error,(long)error.errorCode);

        

        switch (state) {

            case State_ConnectSuccess:{

                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onConnected object:[ECError errorWithCode:ECErrorType_NoError]];}

                break;

            case State_Connecting:

                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onConnected object:[ECError errorWithCode:ECErrorType_Connecting]];

                break;

            case State_ConnectFailed:{

                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onConnected object:error];

            }

                break;

            default:

                break;

        }

        

    }

     

    #endif

     

    /**

     @brief 个人信息版本号

     @param version 服务器上的个人信息版本号

     */

    -(void)onServicePersonVersion:(unsigned long long)version {

        if ([DemoGlobalClass sharedInstance].dataVersion==0 && version==0) {

            [DemoGlobalClass sharedInstance].isNeedSetData = YES;

            [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_needInputName object:nil];

        } else if (version>[DemoGlobalClass sharedInstance].dataVersion) {

            [[ECDevice sharedInstance] getPersonInfo:^(ECError *error, ECPersonInfo *person) {

                if (error.errorCode == ECErrorType_NoError) {

                    [DemoGlobalClass sharedInstance].dataVersion = person.version;

                    [DemoGlobalClass sharedInstance].birth = person.birth;

                    [DemoGlobalClass sharedInstance].nickName = person.nickName;

                    [DemoGlobalClass sharedInstance].sex = person.sex;

                    [DemoGlobalClass sharedInstance].sign = person.sign;

                }

            }];

        }

    }

     

    /**

     @brief 最新软件版本号

     @param version 软件版本号

     @param mode 更新模式  1:手动更新 2:强制更新

     */

    -(void)onSoftVersion:(NSString*)version andUpdateMode:(NSInteger)mode {

        

        MCLog(@"SoftVersion=%@ mode=%ld",version, (long)mode);

        NSComparisonResult result = [version compare:kSofeVer];

        if (result == 1) {

            [DemoGlobalClass sharedInstance].isNeedUpdate=YES;

            [[AppDelegate shareInstance] updateSoftAlertViewShow:@"有新版本发布啦!" isForceUpdate:(mode==2)];

        }

    }

     

    -(void)onReceiveDeskMessage:(ECMessage*)message{

        if (message.from.length==0) {

            return;

        }

        

        if (message.messageBody.messageBodyType == MessageBodyType_Text) {

            ECTextMessageBody * textmsg = (ECTextMessageBody *)message.messageBody;

            textmsg.text = [[EmojiConvertor sharedInstance] convertEmojiSoftbankToUnicode:textmsg.text];

        }

        

    //#warning 时间全部转换成本地时间

        if (message.timestamp) {

            NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];

            NSTimeInterval tmp =[date timeIntervalSince1970]*1000;

            message.timestamp = [NSString stringWithFormat:@"%lld", (long long)tmp];

        }

        

        [[DeviceDBHelper sharedInstance] addNewMessage:message andSessionId:self.sessionId];

        

        [self playRecMsgSound:message.sessionId];

        

        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onMesssageChanged object:message];

        

        if(message.messageBody.messageBodyType > MessageBodyType_Text){

            ECFileMessageBody *body = (ECFileMessageBody*)message.messageBody;

            body.displayName = body.remotePath.lastPathComponent;

            [[DeviceChatHelper sharedInstance] downloadMediaMessage:message andCompletion:nil];

        }

    }

     

    /**

     @brief 接收即时消息代理函数

     @param message 接收的消息

     */

    //#warning mark  

    -(void)onReceiveMessage:(ECMessage*)message

    {

        

     

        BOOL  isJin=YES;

        switch (message.messageBody.messageBodyType) {

            case MessageBodyType_Text:

                break;

            case MessageBodyType_Voice:

                break;

            case MessageBodyType_Video:

                break;

            case MessageBodyType_Image:

                break;

     

         case MessageBodyType_File: {

           

    //#warning 根据文件的后缀名来获取多媒体消息的类型 麻烦 缺少displayName

             //gzz0203.card  改成 .png

                ECFileMessageBody *body = (ECFileMessageBody *)message.messageBody;

             

            //gzz0607  ios7 会崩溃

             if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){

             

                 if ([body.displayName containsString:@".card"]) {

                     MCLog(@"dddddd body  ");

                     isJin=NO;

                     break;

                 }

                 

             

             }else{

             

                 if ([body.displayName rangeOfString:@".card"].location == NSNotFound) {

                     MCLog(@"==不做处理==");

                 } else {

                     

                     

                     MCLog(@"包含  ====");

                     isJin=NO;

                     break;

                 }

                 

             

             

             }

     

            }

                break;

            default:

                break;

     

        }

        MCLog(@"======gzz0302 isjin========%d",isJin);

        

        if (!isJin) {

            return ;

        }

        

        

        //gzz  原来的 上面是 我写的

       

    //    扩展字段json 格式

        /*{

         "type":“1”

         "userData":{

         "uuid":“123”

         “name”:"张三"

         “photo”://头像

         }

         }

     

     */

        

    //    type1:

    //    专家同意患者的随访申请。

    //    type2:

    //    专家拒绝患者的随访申请。

    //    

    //    type3:

    //    专家抢答成功公益咨询。

    //    type4:

    //    专家解除患者的随访关系。

    //    type5:

    //    患者解除专家的随访关系。

    //    type6:

    //    订单消息

    //    type=7:

    //    系统消息

    //    type=8:

    //    患者申请专家随访

        

        

        MCLog(@"message 接收即时消息代理函数%@",message.userData);  //2,1,1,803c48e6fc5643d792a4aafe38f217fb

        // //send_type(发送方类型 1.患者 2.专家),receiver_type(接收方类型 1.患者 2.专家),chat_from(来源1.公益咨询 2.随访 3.vip,chat_from_uuid(如果是公益咨询,则存uuid,否则0

       

     

        if ([message.from rangeOfString:@"#"].location == NSNotFound) {

            

            return;//gzz0728

        }else{

            //包含

        }

        NSString *syssesside = [NSString stringWithFormat:@"%@",message.sessionId];

        if ([syssesside isEqualToString:@"f81e64e19fd54525be857aa49c724582"]||[syssesside isEqualToString:@"a46c069b8179419db8d9aac07550dafb"]||[syssesside isEqualToString:@"3219a37e63f14ebfae586de7676ab550"]||[syssesside isEqualToString:@"8f144d2f8f8b4e9484869492a7567ce4"]||[syssesside isEqualToString:@"c4957541a3294caebf298f235cfe106d"]) {

            

            

            

            NSData *dataer = [message.userData dataUsingEncoding:NSUTF8StringEncoding];

            

            NSDictionary *dicer = [NSJSONSerialization JSONObjectWithData:dataer options:NSJSONReadingAllowFragments error:nil];

            MCLog(@"----即时系统消息-if----%@-dicer-%@==",syssesside,dicer);

            NSMutableDictionary *dicmut = [NSMutableDictionary dictionary];

            [dicmut setDictionary:dicer[@"userData"]];

            [dicmut setValue:dleaexp.uuidstring forKey:@"benuuid"];

     

            NSString *strchaQingchu = [NSString stringWithFormat:@"%@",dicer[@"type"]];

            

            

            NSDictionary *dicUser=[NSDictionary dictionaryWithDictionary:dicer[@"userData"]];

            

            //gzz0303 扩展字段专家同意成为随访医生

            if ([strchaQingchu isEqualToString:@"1"]) {

                

                

                //gzz0302  即时消息  添加随访 系统推送

                NSUserDefaults *expertInfo=[NSUserDefaults standardUserDefaults];

                [expertInfo synchronize];

                if ([[expertInfo objectForKey:@"expertInfo"] isKindOfClass:[NSArray class]]) {

                    NSMutableArray *arrY=  [NSMutableArray  arrayWithArray:[expertInfo objectForKey:@"expertInfo"]];;

     

    //

                    NSString *sss=[NSString stringWithFormat:@"%@",[dicUser objectForKey:@"uuid"]];

                    [arrY addObject:sss];

                    

                    MCLog(@"添加随访专家  即时  系统推送 gzz0303 专家个数%zd",arrY.count);

                    

                    [expertInfo setObject:arrY forKey:@"expertInfo"];

                    

                }

                

                

            

                

     

            }

            

            

            if ([strchaQingchu isEqualToString:@"4"]) {    //解除关系时清除红点

                REqumutarr = [[NSMutableArray alloc]initWithArray:[userDefaul objectForKey:@"FLLOWDOCEXPERT"]];

                

                NSString *measeguuid = [NSString stringWithFormat:@"%@",[Dlpontlerexple shareIndence].uuidstring];

                //gzz0310 专家的uuid  即时

                NSString *sessiondid = [NSString stringWithFormat:@"8a48b5514fba2f87014fca72dec021e4#%@",[dicer[@"userData"]objectForKey:@"uuid"]];

     

                

                

                //gzz0302  即时消息  解除随访关系时 去掉该医生

                NSUserDefaults *expertInfo=[NSUserDefaults standardUserDefaults];

                [expertInfo synchronize];

                if ([[expertInfo objectForKey:@"expertInfo"] isKindOfClass:[NSArray class]]) {

                    NSMutableArray *arrY=  [NSMutableArray  arrayWithArray:[expertInfo objectForKey:@"expertInfo"]];;

                    for (int i=0; i<arrY.count; i++) {

                        NSString *strnnn=[NSString stringWithFormat:@"%@",[arrY objectAtIndex:i]];

                        if ([strnnn isEqualToString:[dicer[@"userData"]objectForKey:@"uuid"]]) {

                            [arrY removeObjectAtIndex:i];

                            

                        }

                    }

                    MCLog(@"解除随访专家  gzz0303 专家个数%zd",arrY.count);

     

                    [expertInfo setObject:arrY forKey:@"expertInfo"];

                    

                }

                //gzz0303 解除随访之后 去掉小红点

                [[NSNotificationCenter defaultCenter] postNotificationName:@"CancelExpertDot" object:nil];

     

                

                

                

                for (int i=0; i<REqumutarr.count; i++) {

                    NSString *messageforms = [NSString stringWithFormat:@"%@",[[REqumutarr objectAtIndex:i] objectForKey:@"messageuuid"]];

                    

     

     

                    NSString *gxmessageforms = [NSString stringWithFormat:@"%@",[[REqumutarr objectAtIndex:i] objectForKey:@"messagefroms"]];

                    

                    if ([messageforms isEqualToString:measeguuid]&&[gxmessageforms isEqualToString:sessiondid]) {

                        [REqumutarr removeObjectAtIndex:i];

                        

                    }

                }

                //    if ([REqumutarr containsObject:self.sessionId]) {

                //        [REqumutarr removeObject:self.sessionId];

                //

                //    }

                [userDefaul setValue:REqumutarr forKey:@"FLLOWDOCEXPERT"];//gzz 0310 1forkey 即时

                //    [nsuserdf synchronize];

                

                

                PulistChatMutarr = [[NSMutableArray alloc]initWithArray:[userDefaul objectForKey:@"PUBLICBENEFITCONSULT"]];

                

                for (int i=0; i<PulistChatMutarr.count; i++) {

                    NSString *messageforms = [NSString stringWithFormat:@"%@",[[PulistChatMutarr objectAtIndex:i] objectForKey:@"messageuuid"]];

                    NSString *gxmessageforms = [NSString stringWithFormat:@"%@",[[PulistChatMutarr objectAtIndex:i] objectForKey:@"messagefroms"]];

                    

                    if ([messageforms isEqualToString:measeguuid]&&[gxmessageforms isEqualToString:sessiondid]) {

                        [PulistChatMutarr removeObjectAtIndex:i];

                        

                    }

                }

                

                //    if ([PulistChatMutarr containsObject:self.sessionId]) {

                //        [PulistChatMutarr removeObject:self.sessionId];

                //    }

                [userDefaul setValue:PulistChatMutarr forKey:@"PUBLICBENEFITCONSULT"];//gzz0203  22222  public consult

                [userDefaul synchronize];

            }

     

            

            

            NSMutableArray *mutarr = [[NSMutableArray alloc]initWithArray:[userDefaul objectForKey:@"lixianxitongxiaoxi"]];

            [mutarr addObject:dicmut];

     

            [userDefaul setValue:mutarr forKey:@"lixianxitongxiaoxi"];//gzz0203  333即时系统消息

            [userDefaul synchronize];

     

            [[NSNotificationCenter defaultCenter]postNotificationName:@"LIXIANXITONGXIAOXINOTIFICATION" object:nil];

     

            

            

        }

        

        

        else{

            

            MCLog(@"----------gzz0302----else---------------");

            

            

        NSArray *Typform = [message.userData componentsSeparatedByString:@","];

        if (Typform.count==0|| Typform.count == 1) {//gzz0728

            

        }

        else{

    //        //gzz0302 获取想要的东西   last @"----即时系统消息-----%@-dicer-%@=="

    //        NSData *dataer = [message.userData dataUsingEncoding:NSUTF8StringEncoding];

    //        

    //        NSDictionary *dicer = [NSJSONSerialization JSONObjectWithData:dataer options:NSJSONReadingAllowFragments error:nil];

    //        MCLog(@"---gzz0302  else -即时系统消息-----%@-dicer-%@==",syssesside,dicer);

            

            //gzz0303 根据uuid jishi 判断是否是专家 提示我的专家那里

            NSArray *array=[syssesside componentsSeparatedByString:@"#"];

            NSString  *two=[array objectAtIndex:1];

            

            NSUserDefaults *expertInfo=[NSUserDefaults standardUserDefaults];

            [expertInfo synchronize];

            NSMutableArray *arrY=[NSMutableArray array];

            if ([[expertInfo objectForKey:@"expertInfo"] isKindOfClass:[NSArray class]]) {

             arrY =  [NSMutableArray  arrayWithArray:[expertInfo objectForKey:@"expertInfo"]];;

            }

            

            if ([arrY containsObject:two]) {

            

                fllowupDoc  = [[NSMutableArray alloc] initWithArray:[userDefaul objectForKey:@"FLLOWDOCEXPERT"]];

                //            fllowupDoc = [NSMutableArray array];

                NSMutableArray *mutarr = [NSMutableArray array];

                NSMutableDictionary *dicer = [NSMutableDictionary dictionary];

                for (int i=0; i<fllowupDoc.count; i++) {

                    [mutarr addObject:[[fllowupDoc objectAtIndex:i] objectForKey:@"messagefroms"]];

                }

                

                

                

                if (![mutarr containsObject:message.from]) {

                    //                [fllowupDoc addObject:message.from];

                    [dicer setValue:message.from forKey:@"messagefroms"];

                    [dicer setValue:dleaexp.uuidstring forKey:@"messageuuid"];

                    [fllowupDoc addObject:dicer];

                    

                }

                MCLog(@"随访医生--0510--%@----===----%@--",fllowupDoc,dicer);

                

                

                [userDefaul setValue:fllowupDoc forKey:@"FLLOWDOCEXPERT"];//gzz 0310 2forkey 即时

                [userDefaul synchronize];

                [[NSNotificationCenter defaultCenter ]postNotificationName:@"EXPERTDOCTOR" object:nil];

                

     

            }

            else{//以前的

            

                NSString *strType = [NSString stringWithFormat:@"%@",Typform[2]];

                if ([strType isEqualToString:@"1"]) {

                    MCLog(@"gzz0302公益咨询");

                    PublicArr  = [[NSMutableArray alloc] initWithArray:[userDefaul objectForKey:@"PUBLICBENEFITCONSULT"]];

                    

                    NSMutableArray *mutarr = [NSMutableArray array];

                    NSMutableDictionary *dicer = [NSMutableDictionary dictionary];

                    for (int i=0; i<PublicArr.count; i++) {

                        [mutarr addObject:[[PublicArr objectAtIndex:i] objectForKey:@"messagefroms"]];

                    }

                    

                    if (![mutarr containsObject:message.from]) {

                        [dicer setValue:message.from forKey:@"messagefroms"];

                        [dicer setValue:dleaexp.uuidstring forKey:@"messageuuid"];

                        [PublicArr addObject:dicer];

                        

                    }

                    [userDefaul setValue:PublicArr forKey:@"PUBLICBENEFITCONSULT"];

                    [userDefaul synchronize];

                    [[NSNotificationCenter defaultCenter ]postNotificationName:@"NOTIFICATIONPUBLICBENEFITCONSULT" object:nil];

                }

                

                

                

                if ([strType isEqualToString:@"2"]) {

                    fllowupDoc  = [[NSMutableArray alloc] initWithArray:[userDefaul objectForKey:@"FLLOWDOCEXPERT"]];

                    //            fllowupDoc = [NSMutableArray array];

                    NSMutableArray *mutarr = [NSMutableArray array];

                    NSMutableDictionary *dicer = [NSMutableDictionary dictionary];

                    for (int i=0; i<fllowupDoc.count; i++) {

                        [mutarr addObject:[[fllowupDoc objectAtIndex:i] objectForKey:@"messagefroms"]];

                    }

                    

                    

                    

                    if (![mutarr containsObject:message.from]) {

                        //                [fllowupDoc addObject:message.from];

                        [dicer setValue:message.from forKey:@"messagefroms"];

                        [dicer setValue:dleaexp.uuidstring forKey:@"messageuuid"];

                        [fllowupDoc addObject:dicer];

                        

                    }

                    MCLog(@"随访医生--05101--%@----===----%@--",fllowupDoc,dicer);

                    

                    

                    [userDefaul setValue:fllowupDoc forKey:@"FLLOWDOCEXPERT"];  //gzz 0310 3forkey 即时

                    [userDefaul synchronize];

                    [[NSNotificationCenter defaultCenter ]postNotificationName:@"EXPERTDOCTOR" object:nil];

                    

                    

                }

                if ([strType isEqualToString:@"3"]) {

                    MCLog(@"vip");//gzz0405vip是不是也是专家?是的

                }

                

                

            }

            

            

            

           

     

        }

            

            

            

        }

        

        

        

        

        

        

        

        

        

        

        

        if (message.from.length==0) {

            return;

        }

    //    message.from = [NSString stringWithFormat:@"8a48b5514fba2f87014fca72dec021e4#%@",message.from];

        MCLog(@"---message.from-gzz0302-%@--",message.from); //消息来源用户账号gzz0310

     

        if (message.messageBody.messageBodyType == MessageBodyType_Text) {

            ECTextMessageBody * textmsg = (ECTextMessageBody *)message.messageBody;

            textmsg.text = [[EmojiConvertor sharedInstance] convertEmojiSoftbankToUnicode:textmsg.text];

        }

        

    //#warning 时间全部转换成本地时间

        if (message.timestamp) {

            NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];

            NSTimeInterval tmp =[date timeIntervalSince1970]*1000;

            message.timestamp = [NSString stringWithFormat:@"%lld", (long long)tmp];

        }

        

        [[DeviceDBHelper sharedInstance] addNewMessage:message andSessionId:self.sessionId];

        

        [self playRecMsgSound:message.sessionId];

        

        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onMesssageChanged object:message];

        

        if(message.messageBody.messageBodyType > MessageBodyType_Text){

            ECFileMessageBody *body = (ECFileMessageBody*)message.messageBody;

            body.displayName = body.remotePath.lastPathComponent;

            [[DeviceChatHelper sharedInstance] downloadMediaMessage:message andCompletion:nil];

        }

    }

     

    /**

     @brief 离线消息数

     @param count 消息数

     */

    -(void)onOfflineMessageCount:(NSUInteger)count{

        MCLog(@"onOfflineMessageCount=gzz离线消息数=%lu",(unsigned long)count);

        self.offlineCount = count;

    }

     

    /**

     @brief 需要获取的消息数

     @return 消息数 -1:全部获取 0:不获取

     */

    -(NSInteger)onGetOfflineMessage{

        NSInteger retCount = -1;

        if (self.offlineCount!=0) {

            /*

            if (self.offlineCount>100) {

                retCount = 100;

            }

            */

            dispatch_async(dispatch_get_main_queue(), ^{

                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_haveHistoryMessage object:nil];

            });

        }

        return retCount;

    }

     

    /**

     @briefgzz0728 离线消息 接收离线消息代理函数

     @param message 接收的消息

     */

    -(void)onReceiveOfflineMessage:(ECMessage*)message{

        

        BOOL  isJin=YES;//gzz0202

        switch (message.messageBody.messageBodyType) {

            case MessageBodyType_Text:

                break;

            case MessageBodyType_Voice:

                break;

            case MessageBodyType_Video:

                break;

            case MessageBodyType_Image:

                break;

                

            case MessageBodyType_File: {

    //#warning 根据文件的后缀名来获取多媒体消息的类型 麻烦 缺少displayName

                ECFileMessageBody *body = (ECFileMessageBody *)message.messageBody;

    //            if ([body.displayName containsString:@".card"]) {gzz0607

    //                MCLog(@"dddddd body  ");

    //                isJin=NO;

    //                break;

    //            }

                

                //gzz0607  ios7 会崩溃

                if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){

                    

                    if ([body.displayName containsString:@".card"]) {

                        MCLog(@"dddddd body  ");

                        isJin=NO;

                        break;

                    }

     

                    

                }else{

                    

                    if ([body.displayName rangeOfString:@".card"].location == NSNotFound) {

                        MCLog(@"==不做处理==");

                    } else {

                        

                        

                        MCLog(@"包含  ====");

                        isJin=NO;

                        break;

                    }

                }

            }

                break;

            default:

                break;

                

        }

        

        if (!isJin) {

            return ;

        }

        

        

        //gzz0202  原来的 上面是 我写的

     

        

        

        MCLog(@"message gzz 接收离线消息代理函数%@--content%@",message.from,message.userData);

        devieInt++;

        

        if ([message.from rangeOfString:@"#"].location == NSNotFound) {

        

            return;//gzz0728

        }else{

        //包含

        }

        if (devieInt<2) {

            

        

        NSUserDefaults * usedefauel =[NSUserDefaults standardUserDefaults];

        NSString * messASound = [NSString stringWithFormat:@"yishengxiaoxidoc%@",[usedefauel objectForKey:@"MyUuid"]];

        NSString *isMessageShake = [NSString stringWithFormat:@"xitongxiaoxiSYS%@",[usedefauel objectForKey:@"MyUuid"]];

        NSString * messASoundsa = [NSString stringWithFormat:@"%@",[usedefauel objectForKey:messASound]];

        NSString *isMessageShakesa = [NSString stringWithFormat:@"%@",[usedefauel objectForKey:isMessageShake]];

        if ([messASoundsa isEqualToString:@"2"]||[isMessageShakesa isEqualToString:@"2"]) {

            // 声音

            [DemoGlobalClass sharedInstance].isMessageSound = NO;

            // 不震动no

            [DemoGlobalClass sharedInstance].isMessageShake = NO;

            MCLog(@"guan");

        }else{

            

            

            // 声音yes

            [DemoGlobalClass sharedInstance].isMessageSound = YES;

            // 震动

            [DemoGlobalClass sharedInstance].isMessageShake = YES;

            AudioServicesPlaySystemSound(receiveSound);

            AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);

     

            MCLog(@"");

        }

        

        }

        

        

        

        MCLog(@"%d--gzz0728--int",devieInt);

        NSString *syssesside = [NSString stringWithFormat:@"%@",message.sessionId];

        if ([syssesside isEqualToString:@"f81e64e19fd54525be857aa49c724582"]||[syssesside isEqualToString:@"a46c069b8179419db8d9aac07550dafb"]||[syssesside isEqualToString:@"3219a37e63f14ebfae586de7676ab550"]||[syssesside isEqualToString:@"8f144d2f8f8b4e9484869492a7567ce4"]||[syssesside isEqualToString:@"c4957541a3294caebf298f235cfe106d"]) {

            

            

            NSData *dataer = [message.userData dataUsingEncoding:NSUTF8StringEncoding];

     

            NSDictionary *dicer = [NSJSONSerialization JSONObjectWithData:dataer options:NSJSONReadingAllowFragments error:nil];

            NSMutableDictionary *dicermut = [NSMutableDictionary dictionary];

    //        NSMutableDictionary *dicer = [NSJSONSerialization JSONObjectWithData:dataer options:NSJSONReadingAllowFragments error:nil];

            [dicermut setDictionary:dicer[@"userData"]];

     

            [dicermut setValue:[Dlpontlerexple shareIndence].uuidstring forKey:@"benuuid"];

     

     

            NSMutableArray *mutarr = [[NSMutableArray alloc]initWithArray:[userDefaul objectForKey:@"lixianxitongxiaoxi"]];

            [mutarr addObject:dicermut];

            MCLog(@"----离线系统消息-----%@--==dicer---%@---dicermut--%@---mutarr-%@----",syssesside,dicer,dicermut,mutarr);

     

            

            //gzz0203 d第一次离线 系统消息

            [userDefaul setValue:mutarr forKey:@"lixianxitongxiaoxi"];

            [userDefaul synchronize];

            

            

            

            

            //gzz0303 扩展字段专家同意成为随访医生  last if ([strchaQingchu isEqualToString:@"1"]){}

            NSDictionary *dicUser=[NSDictionary dictionaryWithDictionary:dicer[@"userData"]];

            

            NSString *strchaQingchu = [NSString stringWithFormat:@"%@",dicer[@"type"]];

     

            if ([strchaQingchu isEqualToString:@"1"]) {

                //gzz0302  lixian  添加随访 系统推送

                NSUserDefaults *expertInfo=[NSUserDefaults standardUserDefaults];

                [expertInfo synchronize];

                if ([[expertInfo objectForKey:@"expertInfo"] isKindOfClass:[NSArray class]]) {

                    NSMutableArray *arrY=  [NSMutableArray  arrayWithArray:[expertInfo objectForKey:@"expertInfo"]];;

                    //                for (int i=0; i<arrY.count; i++) {

                    //                    NSString *strnnn=[NSString stringWithFormat:@"%@",[arrY objectAtIndex:i]];

                    //                    if ([strnnn isEqualToString:[dicer[@"userData"]objectForKey:@"uuid"]]) {

                    //                        [arrY removeObjectAtIndex:i];

                    //

                    //                    }

                    //                }

                    //

                    NSString *sss=[NSString stringWithFormat:@"%@",[dicUser objectForKey:@"uuid"]];

                    [arrY addObject:sss];

                    

                    MCLog(@"添加随访专家  离线  系统推送 gzz0303 专家个数%zd",arrY.count);

                    

                    [expertInfo setObject:arrY forKey:@"expertInfo"];

                    

                }

                

                

            }

            

     

            

            

            

            

    //解除关系时清楚红点

    //        NSString *strchaQingchu = [NSString stringWithFormat:@"%@",dicer[@"type"]];

            if ([strchaQingchu isEqualToString:@"4"]) {

                REqumutarr = [[NSMutableArray alloc]initWithArray:[userDefaul objectForKey:@"FLLOWDOCEXPERT"]];

    //            NSMutableArray *nofitmutrr = [NSMutableArray array];//gzz0317

                

                //    nofitMutarray =[[NSMutableArray alloc]initWithArray:[defaults objectForKey:@"FLLOWDOCEXPERT"]];

                NSString *measeguuid = [NSString stringWithFormat:@"%@",[Dlpontlerexple shareIndence].uuidstring];

    //            NSString *sessiondid = [NSString stringWithFormat:@"%@",[dicer[@"userData"]objectForKey:@"uuid"]];

                //gzz0310 专家的uuid  离线

                NSString *sessiondid = [NSString stringWithFormat:@"8a48b5514fba2f87014fca72dec021e4#%@",[dicer[@"userData"]objectForKey:@"uuid"]];

                

                

                //gzz0302 离线消息  解除随访关系时 去掉该医生

                NSUserDefaults *expertInfo=[NSUserDefaults standardUserDefaults];

                [expertInfo synchronize];

                if ([[expertInfo objectForKey:@"expertInfo"] isKindOfClass:[NSArray class]]) {

                    NSMutableArray *arrY=  [NSMutableArray  arrayWithArray:[expertInfo objectForKey:@"expertInfo"]];;

                    for (int i=0; i<arrY.count; i++) {

                        NSString *strnnn=[NSString stringWithFormat:@"%@",[arrY objectAtIndex:i]];

                        if ([strnnn isEqualToString:[dicer[@"userData"]objectForKey:@"uuid"]]) {

                            [arrY removeObjectAtIndex:i];

                            

                        }

                    }

                    MCLog(@"gzz0303解除随访 离线 专家个数%zd",arrY.count);

     

                    [expertInfo setObject:arrY forKey:@"expertInfo"];

                    

                }

                

                //gzz0303 解除随访之后 去掉小红点

                [[NSNotificationCenter defaultCenter] postNotificationName:@"CancelExpertDot" object:nil];

                

                

                for (int i=0; i<REqumutarr.count; i++) {

                    NSString *messageforms = [NSString stringWithFormat:@"%@",[[REqumutarr objectAtIndex:i] objectForKey:@"messageuuid"]];

                    NSString *gxmessageforms = [NSString stringWithFormat:@"%@",[[REqumutarr objectAtIndex:i] objectForKey:@"messagefroms"]];

                    

                    if ([messageforms isEqualToString:measeguuid]&&[gxmessageforms isEqualToString:sessiondid]) {

                        [REqumutarr removeObjectAtIndex:i];

                        

                    }

                }

                //    if ([REqumutarr containsObject:self.sessionId]) {

                //        [REqumutarr removeObject:self.sessionId];

                //

                //    }

                [userDefaul setValue:REqumutarr forKey:@"FLLOWDOCEXPERT"];//gzz 0310 4forkey 离线

                //    [nsuserdf synchronize];

                

                

                PulistChatMutarr = [[NSMutableArray alloc]initWithArray:[userDefaul objectForKey:@"PUBLICBENEFITCONSULT"]];

                

                for (int i=0; i<PulistChatMutarr.count; i++) {

                    NSString *messageforms = [NSString stringWithFormat:@"%@",[[PulistChatMutarr objectAtIndex:i] objectForKey:@"messageuuid"]];

                    NSString *gxmessageforms = [NSString stringWithFormat:@"%@",[[PulistChatMutarr objectAtIndex:i] objectForKey:@"messagefroms"]];

                    

                    if ([messageforms isEqualToString:measeguuid]&&[gxmessageforms isEqualToString:sessiondid]) {

                        [PulistChatMutarr removeObjectAtIndex:i];

                        

                    }

                }

                

                //    if ([PulistChatMutarr containsObject:self.sessionId]) {

                //        [PulistChatMutarr removeObject:self.sessionId];

                //    }

                [userDefaul setValue:PulistChatMutarr forKey:@"PUBLICBENEFITCONSULT"];

                [userDefaul synchronize];

            }

            

     

            

            

            [[NSNotificationCenter defaultCenter]postNotificationName:@"LIXIANXITONGXIAOXINOTIFICATION" object:nil];

            

            

        }

        

        

        

        else{

        NSArray *Typform = [message.userData componentsSeparatedByString:@","];

       

    //    if (Typform.count==0) {//gzz0728  message gzz 接收离线消息代理函数8a48b5514fba2f87014fca72dec021e4#Dnjvc5Y1Txz39byt5rn--contentfileName=2016-6-28-14-42-38.mp4

            if (Typform.count==0 || Typform.count == 1) {

            

        }

        else{

    //        /gzz0303 根据uuid jishi 判断是否是专家 提示我的专家那里

            NSArray *array=[syssesside componentsSeparatedByString:@"#"];

            NSString  *two=[array objectAtIndex:1];

            

            NSUserDefaults *expertInfo=[NSUserDefaults standardUserDefaults];

            [expertInfo synchronize];

            NSMutableArray *arrY=[NSMutableArray array];

            if ([[expertInfo objectForKey:@"expertInfo"] isKindOfClass:[NSArray class]]) {

                arrY =  [NSMutableArray  arrayWithArray:[expertInfo objectForKey:@"expertInfo"]];;

            }

            

            if ([arrY containsObject:two]) {

                

                fllowupDoc  = [[NSMutableArray alloc] initWithArray:[userDefaul objectForKey:@"FLLOWDOCEXPERT"]];

                //            fllowupDoc = [NSMutableArray array];

                NSMutableArray *mutarr = [NSMutableArray array];

                NSMutableDictionary *dicer = [NSMutableDictionary dictionary];

                for (int i=0; i<fllowupDoc.count; i++) {

                    [mutarr addObject:[[fllowupDoc objectAtIndex:i] objectForKey:@"messagefroms"]];

                }

                

                

                

                if (![mutarr containsObject:message.from]) {

                    //                [fllowupDoc addObject:message.from];

                    [dicer setValue:message.from forKey:@"messagefroms"];

                    [dicer setValue:dleaexp.uuidstring forKey:@"messageuuid"];

                    [fllowupDoc addObject:dicer];

                    

                }

                MCLog(@"随访医生--05102--%@----===----%@--",fllowupDoc,dicer);

                

                

                [userDefaul setValue:fllowupDoc forKey:@"FLLOWDOCEXPERT"];//gzz 0310 5forkey  离线

                [userDefaul synchronize];

                [[NSNotificationCenter defaultCenter ]postNotificationName:@"EXPERTDOCTOR" object:nil];

                

                

            }

            else{//以前的

            

            //gzz0728

            

            NSString *strType = [NSString stringWithFormat:@"%@",Typform[2]];

            

            if ([strType isEqualToString:@"1"]) {

                MCLog(@"gzz0302离线公益咨询");

                

              NSMutableArray *PublicArrt  = [[NSMutableArray alloc] initWithArray:[userDefaul objectForKey:@"PUBLICBENEFITCONSULT"]];

                

                NSMutableArray *mutarr = [NSMutableArray array];

                NSMutableDictionary *dicer = [NSMutableDictionary dictionary];

                for (int i=0; i<PublicArrt.count; i++) {

                    [mutarr addObject:[[PublicArrt objectAtIndex:i] objectForKey:@"messagefroms"]];

                }

                

                if (![mutarr containsObject:message.from]) {

                    [dicer setValue:message.from forKey:@"messagefroms"];

                    [dicer setValue:dleaexp.uuidstring forKey:@"messageuuid"];

                    [PublicArrt addObject:dicer];

                    

                }

                [userDefaul setValue:PublicArrt forKey:@"PUBLICBENEFITCONSULT"];

                [userDefaul synchronize];

                [[NSNotificationCenter defaultCenter ]postNotificationName:@"NOTIFICATIONPUBLICBENEFITCONSULT" object:nil];

                

            }

            if ([strType isEqualToString:@"2"]) {

                MCLog(@"随访医生");

    //            fllowupDoc  = [[NSMutableArray alloc] initWithArray:[userDefaul objectForKey:@"FLLOWDOCEXPERT"]];

    //            if (![fllowupDoc containsObject:message.from]) {

    //                [fllowupDoc addObject:message.from];

    //            }

    //            [userDefaul setValue:fllowupDoc forKey:@"FLLOWDOCEXPERT"];

    //            [userDefaul synchronize];

    //            [[NSNotificationCenter defaultCenter ]postNotificationName:@"EXPERTDOCTOR" object:nil];

                

                

               NSMutableArray *fllowupDocl  = [[NSMutableArray alloc] initWithArray:[userDefaul objectForKey:@"FLLOWDOCEXPERT"]];

                //            fllowupDoc = [NSMutableArray array];

                NSMutableArray *mutarr = [NSMutableArray array];

                NSMutableDictionary *dicer = [NSMutableDictionary dictionary];

                for (int i=0; i<fllowupDocl.count; i++) {

                    [mutarr addObject:[fllowupDocl[i] objectForKey:@"messagefroms" ]];

                }

                

                

                

                if (![mutarr containsObject:message.from]) {

                    //                [fllowupDoc addObject:message.from];

                    [dicer setValue:message.from forKey:@"messagefroms"];

                    [dicer setValue:dleaexp.uuidstring forKey:@"messageuuid"];

                    [fllowupDocl addObject:dicer];

     

                }

    //            [fl removeAllObjects];

                MCLog(@"随访医生---05103-%@----===----%@--",fllowupDocl,dicer);

     

                [userDefaul setValue:fllowupDocl forKey:@"FLLOWDOCEXPERT"]; //gzz 0310 6forkey 离线

                [userDefaul synchronize];

                [[NSNotificationCenter defaultCenter ]postNotificationName:@"EXPERTDOCTOR" object:nil];

     

                

            }

            if ([strType isEqualToString:@"3"]) {

                MCLog(@"vip");

            }

     

        }

        

        }

        

        }

        

        

        

        

        if (message.from.length==0) {

            return;

        }

        

        if (message.messageBody.messageBodyType == MessageBodyType_Text) {

            ECTextMessageBody * textmsg = (ECTextMessageBody *)message.messageBody;

            textmsg.text = [[EmojiConvertor sharedInstance] convertEmojiSoftbankToUnicode:textmsg.text];

        }

        

    //#warning 时间全部转换成本地时间

        if (!message.timestamp) {

            NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];

            NSTimeInterval tmp =[date timeIntervalSince1970]*1000;

            message.timestamp = [NSString stringWithFormat:@"%lld", (long long)tmp];

        }

        

        [[DeviceDBHelper sharedInstance] addNewMessage:message andSessionId:self.sessionId];

        

        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onMesssageChanged object:message];

        

        if(message.messageBody.messageBodyType > MessageBodyType_Text){

            ECFileMessageBody *body = (ECFileMessageBody*)message.messageBody;

            body.displayName = body.remotePath.lastPathComponent;

            [[DeviceChatHelper sharedInstance] downloadMediaMessage:message andCompletion:nil];

        }

        

        

        switch(message.messageBody.messageBodyType){

            case MessageBodyType_Text:{

                ECTextMessageBody *msgBody = (ECTextMessageBody *)message.messageBody;

                MCLog(@"收到的是文本消息------%@",msgBody.text);

                break;

            }

            case MessageBodyType_Voice:{

                ECVoiceMessageBody *msgBody = (ECVoiceMessageBody *)message.messageBody;

                MCLog(@"音频文件remote路径------%@",msgBody. remotePath);

                break;

            }

                

            case MessageBodyType_Video:{

                ECVideoMessageBody *msgBody = (ECVideoMessageBody *)message.messageBody;

                MCLog(@"视频文件remote路径------%@",msgBody. remotePath);

                break;

            }

                

            case MessageBodyType_Image:{

                ECImageMessageBody *msgBody = (ECImageMessageBody *)message.messageBody;

                MCLog(@"图片文件remote路径------%@",msgBody. remotePath);

                MCLog(@"缩略图片文件remote路径------%@",msgBody. thumbnailRemotePath);

                break;

            }

                

            case MessageBodyType_File:{

                ECFileMessageBody *msgBody = (ECFileMessageBody *)message.messageBody;

                MCLog(@"文件remote路径------%@",msgBody. remotePath);

                break;

            }

            default:

                break;

        }

        

    }

     

    /**

     @brief 离线消息接收是否完成

     @param isCompletion YES:拉取完成 NO:拉取未完成(拉取消息失败)

     */

    -(void)onReceiveOfflineCompletion:(BOOL)isCompletion {

        dispatch_async(dispatch_get_main_queue(), ^{

            [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_HistoryMessageCompletion object:nil];

        });

        [self playRecMsgSound:nil];

    }

     

    /**

     @brief 客户端录音振幅代理函数

     @param amplitude 录音振幅

     */

    -(void)onRecordingAmplitude:(double) amplitude{

        

        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onRecordingAmplitude object:@(amplitude)];

    }

     

    /**

     @brief 接收群组相关消息

     @discussion 参数要根据消息的类型,转成相关的消息类;

     解散群组、收到邀请、申请加入、退出群组、有人加入、移除成员等消息

     @param groupMsg 群组消息

     */

    -(void)onReceiveGroupNoticeMessage:(ECGroupNoticeMessage *)groupMsg{

        

    //#warning 时间全部转换成本地时间

        NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];

        NSTimeInterval tmp =[date timeIntervalSince1970]*1000;

        groupMsg.dateCreated = [NSString stringWithFormat:@"%lld", (long long)tmp];

        

        [[DeviceDBHelper sharedInstance] addNewGroupMessage:groupMsg];

        if (groupMsg.messageType ==ECGroupMessageType_Dissmiss) {

            

            [[DeviceDBHelper sharedInstance] deleteAllMessageOfSession:groupMsg.groupId];

            

        } else if (groupMsg.messageType == ECGroupMessageType_RemoveMember) {

            

            

            ECRemoveMemberMsg *message = (ECRemoveMemberMsg *)groupMsg;

            if ([message.member isEqualToString:[DemoGlobalClass sharedInstance].userName]) {

                [[DeviceDBHelper sharedInstance] deleteAllMessageOfSession:groupMsg.groupId];

            }

        }

        [self playRecMsgSound:nil];

        

        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onReceivedGroupNotice object:groupMsg];

    }

     

    @end

  • 相关阅读:
    API之绘图函数
    DotNetCharting
    Rule engine
    股票
    PHP
    获取Excel.dll
    Excel develop
    几个不错的开源的.net界面控件[转贴]
    关于EXCEL文件双击打不开的问题
    Regular expression
  • 原文地址:https://www.cnblogs.com/gzz2016/p/5715081.html
Copyright © 2011-2022 走看看