根控制器切换

场景:打电话做被叫这个过程我们需要在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;

}


                 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值