快速搭建Objective-C客户端 编辑文档

在进行本部分前,请确认已阅读《环境配置》相关章节。
本章针对Objective-C 开发者集成QttAudio SDK,适用于iOS应用开发。
一共包含6个关键操作:

  1. 实现频道事件代理
  2. 初始化
  3. 参数配置
  4. 进入频道
  5. 离开频道
  6. 释放资源

1. 实现频道事件代理

实现QttChannelEngineDelegate接口类:

@interface QttChannelEngineDelegateImpl : NSObject<QttChannelEngineDelegate>
- (void)onJoinSuccess:(NSString*)channelName uid:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted;
- (void)onReJoinSuccess:(NSString*)channelName uid:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted;
- (void)onOtherJoin:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted;
- (void)onJoinFail:(int)code message:(NSString*)message;
- (void)onConnectionBreak;
- (void)onConnectionLost;
- (void)onWarning:(int)warn message:(NSString*)message;
- (void)onError:(int)err message:(NSString*)message;
- (void)onLeave;
- (void)onOtherLeave:(NSUInteger)uid role:(QttChannelRole)role;
- (void)onTalking:(NSArray<QttVolumeInfo*> *_Nonnull)volumeInfos userNum:(NSInteger)userNum;
- (void)onMuteStatusChanged:(NSUInteger)uid muted:(bool) muted;
- (void)onRoleStatusChanged:(NSUInteger)uid role:(QttChannelRole)role;
- (void)onNetworkStats:(NSUInteger)uid txQuality:(QttQualityType)txQuality rxQuality:(QttQualityType)rxQuality stat:(QttRtcStat*)stat;
- (void)onAudioRouteChanged:(int)route;
- (void)onSoundStateChanged:(int)state;
- (void)onEffectFinished:(int)effectId;
@end

@implementation QttChannelEngineDelegateImpl
- (void)onJoinSuccess:(NSString*)channelName uid:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted {
//自己加入成功,实现加入频道成功的逻辑
}
- (void)onReJoinSuccess:(NSString*)channelName uid:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted {
//自己重新加入频道成功,实现重新加入频道成功的逻辑
}
- (void)onOtherJoin:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted {
//其他用户加入,实现别人进入频道的逻辑
}
- (void)onJoinFail:(int)code message:(NSString*)message {
//自己加入失败,实现加入频道失败的逻辑
}
- (void)onConnectionBreak {
//实现网络打断的逻辑
}
- (void)onConnectionLost {
//实现网络失去连接的逻辑
}
- (void)onWarning:(int)warn message:(NSString*)message {
//实现处理警告信息的逻辑
}
- (void)onError:(int)err message:(NSString*)message {
//实现处理错误信息的逻辑
}
- (void)onLeave {
//实现退出频道的逻辑
}
- (void)onOtherLeave:(NSUInteger)uid role:(QttChannelRole)role {
//其他用户离开,实现别人离开频道的逻辑
}
- (void)onTalking:(NSArray<QttVolumeInfo*> *_Nonnull)volumeInfos userNum:(NSInteger)userNum {
//实现用户音量提示的逻辑
}
- (void)onMuteStatusChanged:(NSUInteger)uid muted:(bool) muted {
//用户mute状态,实现静音状态改变的逻辑
}
- (void)onRoleStatusChanged:(NSUInteger)uid role:(QttChannelRole)role {
//用户角色状态,实现角色状态改变的逻辑
}
- (void)onNetworkStats:(NSUInteger)uid txQuality:(QttQualityType)txQuality rxQuality:(QttQualityType)rxQuality stat:(QttRtcStat*)stat {
//实现通话网络统计逻辑
}
- (void)onAudioRouteChanged:(int)route {
//实现语音路由变更逻辑
}
- (void)onSoundStateChanged:(int)state {
//实现声音文件播放状态发生改变的逻辑
}
- (void)onEffectFinished:(int)effectId {
//实现音效文件播放完毕的逻辑
}
@end

2. 初始化

请开发者使用自己的AppKey进行初始化

id<QttChannelEngineDelegate> delegate = [[QttChannelEngineDelegateImpl alloc] init];
QttChannelEngine* engine = [QttChannelEngine GetEngineInstance:@"your AppKey" delegate:delegate];
if (engine == nil) {
NSLog(@"QttChannel初始化失败,原因是%@", [QttChannelEngine GetError]);
return;
}
NSLog(@"QttChannel初始化成功");

3. 参数设置

//设置为主播,默认为听众
[engine changeRole:TALKER];
//静音状态,默认为非静音
[engine muteLocalAudio:NO];

4. 进入频道

//用户的uid,需要根据您的业务情况进行替换
unsigned int uid = 111111;
//设置频道名称。Appkey相同,并且频道名称相同的用户会进入同一个频道,可以互相通话。
NSString* channelId = @"test1";
[engine join:@"" channelId:channelId uid:uid];

5. 离开频道

//对应engine join进入频道
[engine leave];

6. 释放资源

//对应QttChannelEngine GetEngineInstance
[QttChannelEngine Destroy];
野狗新手?
立即注册,为你提供安全可靠的实时通信云服务。
没找到需要的文档?
你可以提交工单反馈 或 阅读常见问题