Xamarin iOS get status back of a phone call

后端 未结 1 1923
一整个雨季
一整个雨季 2021-01-24 15:31

Is there a way to get the call status back after a call is made from an app. I am using following to make a call

  NSUrl url = new NSUrl(\"tel://\" + phoneStr);         


        
相关标签:
1条回答
  • 2021-01-24 16:07

    On iOS 10+ We can use CXCallObserver to capture the event when user make a phone call like:

    //Make sure both CXCallObserver and ObserverDelegate a strong reference
    private CXCallObserver callObserver;
    private MyCallObserverDelegate myCallDelegate;
    
    callObserver = new CXCallObserver();
    myCallDelegate = new MyCallObserverDelegate();
    callObserver.SetDelegate(myCallDelegate, null);
    

    Implement the delegate for CXCallObserver:

    public class MyCallObserverDelegate : CXCallObserverDelegate
    {
        public override void CallChanged(CXCallObserver callObserver, CXCall call)
        {
            Console.WriteLine(call.Outgoing);
            Console.WriteLine(call.HasConnected);
            Console.WriteLine(call.OnHold);
            Console.WriteLine(call.HasEnded);
        }
    }
    

    But unfortunately, it will not fire when user click cancel.

    After user click the button(cancel or call), the app will fire DidBecomeActiveNotification, so I recommend you create a delay method when DidBecomeActiveNotification fires. Then we can detect which button user clicks:

    NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidBecomeActiveNotification, async (notification) =>
    {
        await Task.Delay(500);
        detectCalling();
    });
    

    In early time we can define a field bool isDialing = false, if CallChanged() fires set it true. At last we can detect the field in detectCalling();.

    0 讨论(0)
提交回复
热议问题