Skip to content
v1
文档/iOS SDK/开发指南

发起与加入通话

发起前确认已经登录、媒体模块可用,且 currentCallSessioncurrentMeetingSession 都为空。成功回调只代表 Session 创建成功,媒体是否接通以 Snapshot 为准。

发起单聊通话

Objective-C:

objc
BIMCallTarget *target = [BIMCallTarget userTargetWithUserID:@"user01"];
BIMCallStartOptions *options =
    [[BIMCallStartOptions alloc] initWithTarget:target
                                      mediaType:BIMCallMediaTypeVideo];
options.initialCameraEnabled = YES;
options.initialMicrophoneMuted = NO;
options.preferredAudioOutput = BIMCallAudioOutputSpeaker;
options.timeout = 30;

[[BIMManager sharedInstance] startCall:options
                                  succ:^(BIMCallSession *session) {
    self.callSession = session;
}
                                  fail:^(int code, NSString *desc) {
    NSLog(@"start call failed: %d %@", code, desc);
}];

Swift:

swift
let target = BIMCallTarget.userTarget(withUserID: "user01")
let options = BIMCallStartOptions(target: target, mediaType: .video)
options.initialCameraEnabled = true

BIMManager.sharedInstance().startCall(options: options) { session in
    self.callSession = session
} fail: { code, desc in
    print("start call failed: \(code) \(desc)")
}

发起群聊或临时多人通话

objc
BIMCallTarget *discussion =
    [BIMCallTarget discussionTargetWithDiscussionID:@"discussion_id"];
BIMCallStartOptions *groupOptions =
    [[BIMCallStartOptions alloc] initWithTarget:discussion
                                      mediaType:BIMCallMediaTypeAudio];
groupOptions.inviteeUserIDs = @[@"user01", @"user02"];

BIMCallTarget *adHoc =
    [BIMCallTarget adHocTargetWithUserIDs:@[@"user01", @"user02"]];

BIMCallStartOptions *adHocOptions =
    [[BIMCallStartOptions alloc] initWithTarget:adHoc
                                      mediaType:BIMCallMediaTypeVideo];

[[BIMManager sharedInstance] startCall:adHocOptions
                                  succ:^(BIMCallSession *session) {
    self.callSession = session;
} fail:^(int code, NSString *desc) {
}];
swift
let discussion = BIMCallTarget.discussionTarget(withDiscussionID: "discussion_id")
let groupOptions = BIMCallStartOptions(target: discussion, mediaType: .audio)
groupOptions.inviteeUserIDs = ["user01", "user02"]

let adHoc = BIMCallTarget.adHocTarget(withUserIDs: ["user01", "user02"])

群聊的 inviteeUserIDs 表示首批邀请成员;临时多人会与 target.userIDs 去重合并。单聊始终只呼叫 target 用户,设置 inviteeUserIDs 会被忽略。

群聊和临时多人创建成功后,发起者会直接进入媒体房间;单聊发起者保持呼出响铃,等远端加入后自动进入媒体。

发起选项

属性默认值说明
target必填单聊用户、群或临时多人目标
mediaType必填AudioVideo
inviteeUserIDs空数组群聊首批成员;单聊忽略
timeout30 秒0 使用 30 秒,正数按向上取整后的整秒提交
subject自动生成1 到 200 字符;空值由 SDK 生成通话主题
customDatanil业务自定义字符串,由通话模型携带
initialMicrophoneMutedNO初始麦克风静音状态
initialCameraEnabledNO初始摄像头状态
preferredAudioOutputSystem系统、听筒、扬声器、蓝牙或耳机

用户 ID 数组会去空、去重并排除当前登录用户。显式主题超过 200 字符会返回 BIMCallErrorInvalidArgument

主动加入进行中的多人通话

joinCallWithID 只用于群聊或临时多人通话,单聊必须通过来电 Session 接听。

objc
[[BIMManager sharedInstance] joinCallWithID:@"call_id"
                                       succ:^(BIMCallSession *session) {
    self.callSession = session;
} fail:^(int code, NSString *desc) {
}];
swift
BIMManager.sharedInstance().joinCall(callID: "call_id") { session in
    self.callSession = session
} fail: { code, desc in
}

接口成功表示信令命令已被接受。媒体真正可用应以 snapshot.state == BIMCallStateConnected 为准。

主动加入时传入的是内部 callID,通常来自 BIMCallMessage.callID 或业务保存的 Snapshot,不是 9 位 meetingNumber