Search code examples
iphoneiosmonoxamarin.ioscore-telephony

Monotouch Phone/Call state?


Is there any way in Monotouch to read the current state on the phone or caller service?

Im trying to find some way of reading if a call is active or a call is on hold etc.

Googling on this haven't turned up anything.

Was looking to run some code snippet like:

if(CallIsActive) {

}
else {

}

My solution:

public static class CallHandler
{
private static CTCallCenter ctc;
private static NSSet calls;

public static void StartListening() {
    Console.WriteLine ("Callhandler is listening");
    ctc = new CTCallCenter ();
    calls = ctc.CurrentCalls;
    ctc.CallEventHandler = new CTCallEventHandler (delegate(CTCall inCTcall) {
            calls = ctc.CurrentCalls;

    });
    }

    public static uint CallCount {
        get {
            return (calls != null) ? calls.Count : 0;
        }
    }

    public static string GetCallState(int CallID) {
        CTCall[] callArr = calls.ToArray<CTCall>();
        CTCall call = callArr[CallID];
        return call.CallState;

    }
}

Run CallHandler.CallCount to get current callcount and GetCallState(0) for first call etc.


Solution

  • I think you're looking for the CoreTelephony framework. There is an Apple sample that covers it.

    using block-based event handlers to receive call events and carrier changes.
    

    You'll need to convert the code from ObjectiveC to C# (look for callStateToUser).