環(huán)信透?jìng)?/h1>

1、發(fā)透?jìng)飨?/p>

//通過(guò)透?jìng)靼l(fā)送當(dāng)前位置信息給領(lǐng)導(dǎo)

EMChatCommand*shareCommand = [[EMChatCommandalloc]init];

shareCommand.cmd=@"ResponseLocation";//當(dāng)前cmd消息的關(guān)鍵字

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

//設(shè)置要發(fā)給誰(shuí),fromToken是環(huán)信用戶username或者群聊groupid

EMMessage*shareMsg = [[EMMessagealloc]initWithReceiver:_fromTokenbodies:@[shareMsgBody]];

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

//latitude,longitude:獲取到的經(jīng)緯度

shareMsg.ext=@{

@"latitude":[NSStringstringWithFormat:@"%f",lat],

@"longitude":[NSStringstringWithFormat:@"%f",lng],

@"reporttime":_reporttime,

@"track":@""

};

[[EaseMobsharedInstance].chatManagerasyncSendMessage:shareMsgprogress:nil];

2、接收透?jìng)飨?/p>

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

EMCommandMessageBody*body = cmdMessage.messageBodies.firstObject;

//接收員工的即時(shí)位置信息

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在后臺(tái)時(shí)也使用,要在環(huán)信后臺(tái)配置ios證書

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容