Skip to content
EaseMob iOS SDK CallDemo
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
VideoDemo
.gitignore
.travis.yml
readme.md

readme.md

README

被叫方不在线的时候,环信不会主动发推送,而且提供了一个接口告诉上层,对方不在线,之后由用户自己确定如何处理。

用户要先实现 EMCallBuilderDelegate 协议才行。

实现协议流程:

// 实现协议
@interface CallViewController () <EMCallBuilderDelegate>

- (void)viewDidLoad {
	[super viewDidLoad];
   	EMCallOptions *options = [[EMClient sharedClient].callManager getCallOptions];
	options.isSendPushIfOffline = YES; // 设置被叫方离线的时候,要执行回调
	[[EMClient sharedClient].callManager setCallOptions:options];
	[[EMClient sharedClient].callManager setBuilderDelegate:self]; // 实现这个协议目的是为了在对方不在线时收到回调
}

#pragma mark -- EMCallBuilderDelegate
// 对方不在线的时候,sdk会回调该方法
- (void)callRemoteOffline:(NSString *)aRemoteName {
	dispatch_async(dispatch_get_main_queue(), ^{
		[self sendMessageToCalled];
	});
}

// 因为对方不在线,发送通知给对方(如果对方是iOS设备,需要配置推送证书才行,可以参考http://www.imgeek.org/publish/article/825308748)
- (void)sendMessageToCalled {
	if (_offineMessage) {
		NSString *currentName = [[EMClient sharedClient] currentUsername];
		EMTextMessageBody *txtBody = [[EMTextMessageBody alloc] initWithText:_offineMessage];
		EMMessage *msg = [[EMMessage alloc] initWithConversationID:_callEmId from:currentName to:_callEmId body:txtBody ext:nil];
		msg.ext = @{@"em_apns_ext":@{@"em_push_title":_offineMessage}};
		[[EMClient sharedClient].chatManager sendMessage:msg progress:nil completion:nil];
	}
}

具体代码,可以查看CallViewController类,测试方式,用当前项目去呼叫环信AppStore下载的Demo,项目使用Cocoapods集成,使用前需要先pod install,之后打开workspace文件运行项目。

注意:iOS10之后,使用麦克风,摄像头之类硬件都需要添加权限,添加的方式参考项目的info.plist文件

You can’t perform that action at this time.