我正在开发一个使用PJSIP Library
的VOIP_App,它使用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);
}
答案 0 :(得分:1)
您可以通过在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];
});
}