我正在开发一个VOIP_App,它使用PJSIP Library
编写的C-Language
,根据情况自动调用该库中编写的大多数方法。
有一个名为on_incoming_call
的方法自动调用并且用户收到调用,我想为接收调用添加一些用户交互,我需要创建一些callBack,应该在这个方法中调用,方法定义应该用Objective-C
编写。
这是代码片段:
/* Callback called by the library upon receiving incoming call */
static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
pjsip_rx_data *rdata)
{
pjsua_call_info ci;
PJ_UNUSED_ARG(acc_id);
PJ_UNUSED_ARG(rdata);
pjsua_call_get_info(call_id, &ci);
PJ_LOG(3,(THIS_FILE, "....\n\n\n Incoming call from %.*s!! \n\n\n",
(int)ci.remote_info.slen,
ci.remote_info.ptr));
/* Automatically answer incoming calls with 200/OK */
pjsua_call_answer(call_id, 200, NULL, NULL);
}
您可以通过在PJSIP库中发布回调通知来实现您的目标
static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
pjsip_rx_data *rdata){
pjsua_call_info ci;
NSString *callerNumber = [NSString stringWithUTF8String:ci.remote_info.ptr];
[[NSNotificationCenter defaultCenter] postNotificationName:
@"IncomingCall" object:callerNumber];
pjsua_call_answer(call_id, 200, NULL, NULL); //Comment out this line and instead call this in your UIViewController to accept the call on click of some button or whatever UI action you desire
}
现在,您可以在AppDelegate中观察此通知
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(launchIncomingVC:) name:@"IncomingCall" object:nil];
}
然后这个函数显示你的UIViewController接受或拒绝来电
-(void)launchIncomingVC:(NSNotification *) notif
{
NSLog(@"LAUNCH INCOMING CALL VC");
YourViewController *rvc = [[YourViewController alloc] init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryBoardName" bundle:nil];
rvc = [storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerIdentifier"];
rvc.paramCallerNumber = noti.object; //pass the caller number to show it on the incoming view
dispatch_async(dispatch_get_main_queue(), ^{
[self.window makeKeyAndVisible];
UIViewController *topRootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topRootViewController.presentedViewController)
{
topRootViewController = topRootViewController.presentedViewController;
}
[topRootViewController presentViewController:incomingVC animated:YES completion:nil];
});
}