- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将 Agora 集成到我的 iOS Swift 5 应用程序中,基本用例揭示了莫名其妙的行为。假设爱丽丝调用鲍勃,当爱丽丝加入指定用户信息的 channel 时:
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)")
}
info: "alice-userid"
Bob 无法访问以下数据:
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
}
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)")
}
最佳答案
假设您已经在 registerLocalUserAccount:appId:
注册了 Alice 和 Bob。方法。他们都必须加入 joinChannelByUserAccount:token:channelId:joinSuccess:
的 channel 。方法。确保 registerLocalUserAccount:appId:
方法返回 0,表示客户端已成功注册。
现在如 Agora documentation 中所述关于 getUserInfoByUid:withError:
方法:
After a user joins the channel, the SDK gets the user ID and user account of the remote user, caches them in a mapping table object (AgoraUserInfo), and triggers the
didUpdatedUserInfo
callback on the local client. After receiving thedidUpdatedUserInfo
callback, you can call this method to get the user account of the user from the userInfo object by passing in the user ID.
getUserInfoByUid:withError:
的正确时机是什么时候
rtcEngine:didUpdatedUserInfo:withUid:
委托(delegate)方法被调用。
getUserInfoByUid:withError:
在方法体内。
// Assign delegate when instantiating
lazy var agoraKit: AgoraRtcEngineKit = {
AgoraRtcEngineKit.sharedEngine(withAppId: "YourAppID", delegate: self)
}()
// Assign delegate later
agoraKit.delegate = self
// Conform to AgoraRtcEngineDelegate
extension MyClass: AgoraRtcEngineDelegate {
//...
}
registerLocalUserAccount:appId:
方法。
// User with 'bob' username will be registered
let registerResponse: Int32 = agoraKit.registerLocalUserAccount("bob", appId: "YourAppID")
if registerResponse == 0 {
// Successfully registered
} else {
// Failed to register
}
agoraKit.joinChannel(byUserAccount: "bob", token: nil, channelId: "room123") { (channel, uid, elapsed) in
print("User joined channel \(channel) with \(uid). Elapsed time is \(elapsed)ms.")
}
rtcEngine:didUpdatedUserInfo:withUid:
委托(delegate)方法。
// This method will be triggered after Agora SDK
// caches user ID and user account of the remote user.
func rtcEngine(_ engine: AgoraRtcEngineKit, didUpdatedUserInfo userInfo: AgoraUserInfo, withUid uid: UInt) {
var error: AgoraErrorCode = .noError
let userInfoWithUid = agoraKit.getUserInfo(byUid: uid, withError: &error)
if error == .noError {
// Do something with AgoraUserInfo object
}
}
关于ios - AgoraKit 无法发送 `userinfo` 给远程用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62120175/
我正在将 Agora 集成到我的 iOS Swift 5 应用程序中,基本用例揭示了莫名其妙的行为。假设爱丽丝调用鲍勃,当爱丽丝加入指定用户信息的 channel 时: agoraKi
我是一名优秀的程序员,十分优秀!