IOS开发 实现电话呼叫功能以及监听电话状态

时间:2022-09-30 14:06:51

- (void) callBack{

    NSLog(@"呼叫");

    NSString *number = @“10086”;

    //    NSString *num = [[NSString alloc] initWithFormat:@"telprompt://%@",number];

    //    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];

    //实现呼叫之后到app

    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",number]];

    UIWebView *  phoneCallWebView = [[UIWebView allocinitWithFrame:CGRectZero];

    [phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];

    CTCallCenter *callCenter = [[CTCallCenter allocinit];

    callCenter.callEventHandler=^(CTCall* call)

    {

        

        if (call.callState == CTCallStateDisconnected&&connect==0)

        {

            NSLog(@"Call has been disconnected");

        }

        else if (call.callState == CTCallStateConnected)

        {

            NSLog(@"Call has just been connected");

        }

        

        else if(call.callState == CTCallStateIncoming)

        {

            NSLog(@"Call is incoming");

            //self.viewController.signalStatus=NO;

        }

        

        else if (call.callState ==CTCallStateDialing)

        {

            NSLog(@"call is dialing");

        }

        else

        {

            NSLog(@"Nothing is done");

        }

    };


}