根控制器切换

本文介绍了一个基于PJSIP实现的接听电话回调方法,该方法能够在应用程序的任何状态下接收电话,并根据应用当前所处的前台或后台状态采取不同的通知方式。在前台时会直接切换到接听界面,在后台时则通过本地通知提醒用户。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

场景:打电话做被叫这个过程我们需要在app的任何界面都能接受到电话,这时候就需要切换根视图控制器到接听来电页面,下面是我实现的pjsip的接听电话的回调:

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);

    

    DLog(@"incoming_call_state:%d",ci.state);

    PJ_LOG(3,(THIS_FILE,"Incoming call from %.*s!!",(int)ci.remote_info.slen,

              ci.remote_info.ptr));

    

    NSRange range = [[NSStringstringWithFormat:@"%s",ci.remote_info.ptr]rangeOfString:@"sip:"];

    int num = [[[NSStringstringWithFormat:@"%s",ci.remote_info.ptr]

                substringWithRange:NSMakeRange(range.location +range.length,4)] intValue];

    

    DLog(@"phonenum:%d %@ call_id:%d",num,[NSStringstringWithFormat:@"%s",ci.remote_info.ptr],call_id);

    

    [[GlobalsshareInstance] setCallID:call_id];

    [[GlobalsshareInstance] setPhoneNum:num];

    

//后台运行

    if ([[UIApplicationsharedApplication] applicationState]==UIApplicationStateBackground) {

        UILocalNotification* notif = [[UILocalNotificationalloc] init];

        notif.soundName =UILocalNotificationDefaultSoundName;

        notif.alertBody =@"来电";

        notif.applicationIconBadgeNumber =1;

        [[UIApplicationsharedApplication] scheduleLocalNotification:notif];

    }else

    {

        AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate,NULL, NULL,soundCompleteCallback, NULL);

        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

        

        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

        //来电ui动作

        //在跳到主线程

        dispatch_async(dispatch_get_main_queue(), ^{

            callingViewController *cal =[[callingViewControlleralloc] init];

            [cal initWithChild:nil];

            [UIApplicationsharedApplication].keyWindow.rootViewController = cal;

            

            isIncomingCall =YES;

        });


    }

    isIncomingCall =YES;

}


                 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值