OMICALL SDK FOR iOS
OmiKit Pod 向外暴露了 OMICALL 库作为 Cocoapod。
框架最重要的部分是
- 帮助轻松集成到 Omicall。
- 轻松定制 Call UI/UX。
- 默认情况下,它们已包含在所有 iOS 架构中。
- 优化 u 的 voip 编解码器。
- 提供完整的接口,可与核心功能(如声音/铃声/编解码器)交互。
状态
目前处于活跃维护状态
使用
运行
通过 CocoaPods 安装
platform :ios, '13.0'
pod 'OmiKit'
通过 Github 安装
platform :ios, '13.0'
pod 'OmiKit', :git => 'https://github.com/VIHATTeam/OmiKit.git'
使用
设置
第1步: 设置推送通知
- 有关设置细节,请查看此处 Android/IOS 推送通知配置指南。
第2步: 设置 AppDelegate
- Setting Enviroment : it will effect key push notification setting in web base at step 1
- Inject Callkit Provider Delegate
- Inject Voip Push notification listener interace
- Setting Push notification APNS for normal push notification ( we using it in case call cancel from another party)
示例代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#ifdef DEBUG
[OmiClient setEnviroment:KEY_OMI_APP_ENVIROMENT_SANDBOX];
#else
[OmiClient setEnviroment:KEY_OMI_APP_ENVIROMENT_PRODUCTION];
#endif
provider = [[CallKitProviderDelegate alloc] initWithCallManager: [OMISIPLib sharedInstance].callManager ];
voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
pushkitManager = [[PushKitManager alloc] initWithVoipRegistry:voipRegistry];
[self requestPushNotificationPermissions];
[OmiClient setLogLevel:5];
return YES;
}
- (void)requestPushNotificationPermissions
{
// iOS 10+
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
switch (settings.authorizationStatus)
{
// User hasn't accepted or rejected permissions yet. This block shows the allow/deny dialog
case UNAuthorizationStatusNotDetermined:
{
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if(granted)
{
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
}
}];
break;
}
case UNAuthorizationStatusAuthorized:
{
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
break;
}
default:
break;
}
}];
}
When get notification token, we need update setup client:
- (void)application:(UIApplication*)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)devToken
{
// parse token bytes to string
const char *data = [devToken bytes];
NSMutableString *token = [NSMutableString string];
for (NSUInteger i = 0; i < [devToken length]; i++)
{
[token appendFormat:@"%02.2hhX", data[i]];
}
[OmiClient setUserPushNotificationToken:[token copy]];
}
第3步 设置应用程序
包含库
#import <OmiKit/OmiKit-umbrella.h>
当前我们提供两种方式初始化用户扩展以进行调用
- 使用用户名/密码/真实信息初始化
[OmiClient initWithUsername:MY_USERNAME password:MY_PASSWORD realm:MY_REALM];
- 使用API密钥(获取API密钥请联系销售管理员/客户服务)
[OmiClient initWithUUID:(NSString * _Nonnull) fullName:<#(NSString * _Nullable)#> apiKey:<#(NSString * _Nonnull)#>]
要拨打电话(电话或代理电话),我们提供了两种拨打电话的方式
- 启动到实际号码或分机的呼叫
BOOL result = [OmiClient startCall:_callPhoneNumberTextField.text isVideo:FALSE result:^(OMIStartCallStatus status){
// check status here
}];
- 使用用户uuid和API密钥启动呼叫
[OmiClient startCallWithUuid:(NSString * _Nonnull) toUuid isVideo: (BOOL) isVideo result: (void (^)(OMIStartCallStatus status)) completion {
// check status here
}];
启动呼叫的状态遵循以下代码
typedef NS_ENUM(NSInteger, OMIStartCallStatus) {
OMIInvalidUuid,
OMIInvalidPhoneNumber,
OMIMaxRetry,
OMIPermissionDenied,
OMICouldNotFindEndpoint,
OMIAccountRegisterFailed,
OMIStartCallFailed,
OMIStartCallSuccess,
};
通知回调
呼叫通知
1. 要监听我们设置的呼叫事件
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callStateChanged:) name:OMICallStateChangedNotification object:nil];
声明函数监听呼叫状态事件以了解调用确认或邀约状态:通知键:OMICallStateChangedNotification 示例
- (void)callStateChanged: (NSNotification *)notification {
__weak typeof(self)weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
__weak OMICall *call = [[notification userInfo] objectForKey:OMINotificationUserInfoCallKey];
switch(call.callState)
{
case OMICallStateEarly:
OMILogDebug(@"callStateChanged OMICallStateEarly : %@",call.uuid.UUIDString);
break;
case OMICallStateCalling:
OMILogDebug(@"callStateChanged OMICallStateCalling : %@",call.uuid.UUIDString);
break;
case OMICallStateIncoming:{
OMILogDebug(@"callStateChanged OMICallStateIncoming : %@",call.uuid.UUIDString);
break;
}
case OMICallStateConnecting:
OMILogDebug(@"callStateChanged OMICallStateConnecting : %@",call.uuid.UUIDString);
break;
case OMICallStateConfirmed:{
OMILogDebug(@"callStateChanged OMICallStateConfirmed : %@",call.uuid.UUIDString);
break;
}
case OMICallStateDisconnected:
OMILogDebug(@"callStateChanged OMICallStateDisconnected : %@",call.uuid.UUIDString);
break;
}
});
}
2. 监听事件 媒体事件
通知键:OMICallMediaStateChangedNotification 示例
- (void)callMediaStateChanged: (NSNotification *)notification {
__weak typeof(self)weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
OMICallMediaState mediaState = (OMICallMediaState)[[notification userInfo] objectForKey:OMINotificationUserInfoCallMediaStateKey];
switch(mediaState)
{
case OMICallStateMuted:
OMILogDebug(@"OMICallMediaState OMICallStateMuted");
break;
case OMICallStateToggleSpeaker:
OMILogDebug(@"OMICallMediaState OMICallStateToggleSpeaker");
break;
case OMICallStatePermissionCameraDenied:
OMILogDebug(@"OMICallMediaState OMICallStateToggleSpeaker");
break;
case OMICallStatePermissionMicrophoneDenied:
OMILogDebug(@"OMICallMediaState OMICallStateToggleSpeaker");
break;
}
});
}
3. 监听事件 通话未接
[Omiclient setMissedCallBlock:^(OMICall * _Nonnull __weak call) {
<#code#>
}];
4. 监听视频通话状态
当事件发生时,我们需要重新渲染视频屏幕。详细示例请参考这里:https://github.com/VIHATTeam/IOS-Objective-VideoCall-Example
### Listen:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoNotification:) name:OMICallVideoInfoNotification object:nil];
```
### Process:
```ruby
-(void) videoNotification:(NSNotification *) noti {
NSDictionary *dic = [noti userInfo];
NSNumber * state = [dic valueForKey:OMIVideoInfoState];
switch([state intValue]){
case OMIVideoRemoteReady:{
[self startPreview];
break;
}
}
}
### Show Video Preview:
- (void)startPreview {
__weak typeof(self) weakSelf = self;
if(!_remoteVideoRenderView || !_localVideoRenderView) return;
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.remoteVideoRenderView.contentMode = UIViewContentModeScaleAspectFill;
[weakSelf.remoteVideoRenderView setView:[self.videoManager createViewForVideoRemote:weakSelf.remoteVideoRenderView.frame]];
weakSelf.localVideoRenderView.contentMode = UIViewContentModeScaleAspectFill;
[weakSelf.localVideoRenderView setView:[self.videoManager createViewForVideoLocal:weakSelf.localVideoRenderView.frame]];
});
}
5. 监听网络健康状况以更新用户界面提示
我们在MOS评分和设备3级以下计算的信息
Listen:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNetworkHealth:) name:OMICallNetworkQualityNotification object:nil];
Process:
-(void) updateNetworkHealth:(NSNotification *) noti {
NSDictionary *dic = [noti userInfo];
NSNumber * state = [dic valueForKey:OMINotificationNetworkStatusKey];
switch([state intValue]){
case OMINetworkGood:{
[self.networkStatus setImage: [UIImage imageNamed: @"network_best"]];
break;
}
case OMINetworkMedium:{
[self.networkStatus setImage: [UIImage imageNamed: @"network_medium"]];
break;
}
case OMINetworkBad:{
[self.networkStatus setImage: [UIImage imageNamed: @"network_bad"]];
break;
}
}
}
使用噪音消除(当手机电量低时性能会变慢)
[OmiClient setNoiseSuppression:true];
联系开发者
我们很乐意回答您其他的问题,联系方式如下 {[email protected]}
授权
OmiKit 由 VIHATGROUP 反向。