根控制器切换

来源:互联网 发布:什么是百度seo 编辑:程序博客网 时间:2024/05/24 04:16

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