Ios AgoraKit无法向远程用户发送“userinfo”
我正在将Agora集成到我的iOS Swift 5应用程序中,基本用例揭示了令人费解的行为。假设Alice调用Bob,当Alice加入指定了userinfo的频道时:Ios AgoraKit无法向远程用户发送“userinfo”,ios,swift,agora.io,Ios,Swift,Agora.io,我正在将Agora集成到我的iOS Swift 5应用程序中,基本用例揭示了令人费解的行为。假设Alice调用Bob,当Alice加入指定了userinfo的频道时: agoraKit.joinChannel( byToken: nil , channelId: "chan-1234" , info: "alice-userid" , uid: 0 ) { [weak self]
agoraKit.joinChannel(
byToken: nil
, channelId: "chan-1234"
, info: "alice-userid"
, uid: 0
) { [weak self] (sid, uid, elapsed) in
print("\n Join channel ...: for sid: \(sid), uid: \(uid), dt: \(elapsed)")
}
Bob无法在以下位置访问信息:“alice userid”
数据:
func rtcEngine(_ engine: AgoraRtcEngineKit, firstRemoteVideoDecodedOfUid uid:UInt, size:CGSize, elapsed:Int) {
let userInfo = agoraKit.getUserInfo(byUid: uid, withError: nil)
print("added user: \(uid), with userinfo: \(userInfo)") // get uid, nil
}
在Bob方面,userInfo
为零。所以我试着加入用户帐户
agoraKit.registerLocalUserAccount("alice-userid", appId: AppID)
agoraKit.joinChannel(
byUserAccount: "alice-account-data"
, token: nil
, channelId: "chan-1234"
) { [weak self] (sid, uid, elapsed) in
print("\n Join channel ...: for sid: \(sid), uid: \(uid), dt: \(elapsed)")
}
这完全失败了。我在这里引用文档:
在第二种情况下,文档有输入错误,API已过期。假设您已经使用
registerLocalUserAccount:appId:
方法注册了Alice和Bob。它们都必须使用joinChannelByUserAccount:token:channelId:joinSuccess:
方法加入频道。确保registerLocalUserAccount:appId:
方法返回0,这意味着客户端已成功注册
现在,如aboutgetUserInfoByUid:withError:
方法中所述:
用户加入频道后,SDK获取远程用户的用户ID和用户帐户,将其缓存在映射表对象(AgoraUserInfo)中,并在本地客户端上触发didUpdatedUserInfo
回调。在收到didUpdatedUserInfo
回调后,可以调用此方法,通过传入用户ID从userInfo对象获取用户的用户帐户
这意味着调用getUserInfoByUid:withError:
的正确时间是在调用rtcnengine:diddupdatedeserinfo:withUid:
委托方法时
我从您的代码片段中猜测,您的类已经符合AgorartEngineedElegate协议。所以,您所要做的就是实现这个委托方法,并在方法体内部调用getUserInfoByUid:withError:
示例:
步骤1:
使您的类符合AgorartEngineedElegate:
//实例化时分配委托
lazy var agoraKit:AgorartEnginekit={
AgorartEngineKit.sharedEngine(使用AppID:“YourAppID”,委托人:self)
}()
//稍后指派代表
agoraKit.delegate=self
//符合AgorartEngineedElegate
扩展MyClass:AgorartEngineedElegate{
//...
}
步骤2:
使用registerLocalUserAccount:appId:
方法注册用户
//将注册具有“bob”用户名的用户
让registerResponse:Int32=agoraKit.registerLocalUserAccount(“bob”,appId:“YourAppID”)
如果registerResponse==0{
//成功注册
}否则{
//注册失败
}
步骤3:
用户注册成功后加入频道
agoraKit.joinChannel(byUserAccount:“bob”,token:nil,channelId:“room123”){(channel,uid,appeased)在
打印(“用户使用\(uid)加入频道\(频道)。运行时间为\(运行)毫秒”)
}
步骤4:
实现rtcnengine:didUpdatedUserInfo:withUid:
delegate方法
//此方法将在Agora SDK之后触发
//缓存远程用户的用户ID和用户帐户。
func rtcEngine(engine:AgorartEngineKit,didUpdatedUserInfo:AgoraUserInfo,带uid:UInt){
变量错误:AgoraErrorCode=.noError
让userInfoWithUid=agoraKit.getUserInfo(byUid:uid,withError:&error)
如果错误==.noError{
//对AgoraUserInfo对象执行某些操作
}
}
能否提供一个代码示例?我不太明白你的意思。在文档中,我甚至没有看到swift的委托方法。。。()