1、发透传消息
//通过透传发送当前位置信息给领导
EMChatCommand*shareCommand = [[EMChatCommandalloc]init];
shareCommand.cmd=@"ResponseLocation";//当前cmd消息的关键字
EMCommandMessageBody*shareMsgBody = [[EMCommandMessageBodyalloc]initWithChatObject:shareCommand];
//设置要发给谁,fromToken是环信用户username或者群聊groupid
EMMessage*shareMsg = [[EMMessagealloc]initWithReceiver:_fromTokenbodies:@[shareMsgBody]];
shareMsg.messageType=eMessageTypeChat;//单聊或者群聊
//latitude,longitude:获取到的经纬度
shareMsg.ext=@{
@"latitude":[NSStringstringWithFormat:@"%f",lat],
@"longitude":[NSStringstringWithFormat:@"%f",lng],
@"reporttime":_reporttime,
@"track":@""
};
[[EaseMobsharedInstance].chatManagerasyncSendMessage:shareMsgprogress:nil];
2、接收透传消息
-(void)didReceiveCmdMessage:(EMMessage*)cmdMessage{
EMCommandMessageBody*body = cmdMessage.messageBodies.firstObject;
//接收员工的即时位置信息
if([body.actionisEqualToString:@"ResponseLocation"]) {
NSString*latitude = [cmdMessage.extobjectForKey:@"latitude"];
NSString*longitude = [cmdMessage.extobjectForKey:@"longitude"];
NSString*reporttime = [cmdMessage.extobjectForKey:@"reporttime"];
NSMutableDictionary*locationInfo = [[NSMutableDictionaryalloc]init];
[locationInfosetObject:latitudeforKey:@"lat"];
[locationInfosetObject:longitudeforKey:@"lng"];
[locationInfosetObject:reporttimeforKey:@"reporttime"];
[[NSNotificationCenterdefaultCenter]postNotificationName:@"userLocationNotification"object:niluserInfo:locationInfo];
}
}
3、配置
若想APP在后台时也使用,要在环信后台配置ios证书