分享

环信透传

 ____YY____ 2016-03-08

1、        发透传消息

//通过透传发送当前位置信息给领导

        EMChatCommand *shareCommand = [[EMChatCommand alloc] init];

        shareCommand.cmd = @"ResponseLocation";            // 当前cmd消息的关键字

        EMCommandMessageBody *shareMsgBody = [[EMCommandMessageBody alloc] initWithChatObject:shareCommand];

        //设置要发给谁, fromToken是环信用户username或者群聊groupid

        EMMessage *shareMsg = [[EMMessage alloc] initWithReceiver:_fromToken bodies:@[shareMsgBody]];

        shareMsg.messageType = eMessageTypeChat;   // 单聊或者群聊

        //latitude,longitude:获取到的经纬度

        shareMsg.ext = @{

                         @"latitude":[NSString stringWithFormat:@"%f",lat],

                         @"longitude":[NSString stringWithFormat:@"%f",lng],

                         @"reporttime":_reporttime,

                         @"track":@""

                        };

        [[EaseMob sharedInstance].chatManager asyncSendMessage:shareMsg progress:nil];

 

2、        接收透传消息

-(void)didReceiveCmdMessage:(EMMessage *)cmdMessage{

    EMCommandMessageBody *body = cmdMessage.messageBodies.firstObject;

    //接收员工的即时位置信息

    if ([body.action isEqualToString:@"ResponseLocation"]) {

        NSString *latitude = [cmdMessage.ext objectForKey:@"latitude"];

        NSString *longitude = [cmdMessage.ext objectForKey:@"longitude"];

        NSString *reporttime = [cmdMessage.ext objectForKey:@"reporttime"];

       

        NSMutableDictionary *locationInfo = [[NSMutableDictionary alloc] init];

        [locationInfo setObject:latitude forKey:@"lat"];

        [locationInfo setObject:longitude forKey:@"lng"];

        [locationInfo setObject:reporttime forKey:@"reporttime"];

       

        [[NSNotificationCenter defaultCenter] postNotificationName:@"userLocationNotification" object:nil userInfo:locationInfo];

    }

}

 

3、        配置

若想APP在后台时也使用,要在环信后台配置ios证书

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多