How to know a incomming call Xamarin iOS

DAVIS JIMENEZ PETER ALEXANDER 20 Reputation points
2024-04-10T16:55:17.7633333+00:00

Hello, I have a requirement that I must validate if there is a call (normal or VoIP), for Xamarin Android I have:

public bool InCall() {
            var theAudioManager = (AudioManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.AudioService);
            if (theAudioManager.Mode == Mode.InCall || theAudioManager.Mode == Mode.InCommunication) {
                return true;
            } else {
                return false;
            }
        }

Is there a way to do the same on iOS? I have read CallKit but my application does not need to make calls, only to know if there is a call (normal or VoIP)

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,446 Reputation points Microsoft Vendor
    2024-04-11T07:11:16.28+00:00

    Hello,

    If your app is playing an audio/video, you can receive the AVAudioSession.InterruptionNotification, and do something in its callback method. And you cannot detect the system-event if your app is not playing an audio/video.

    Please refer to the following code:

     var player = new AVPlayer(new NSUrl("https://XXXXX"));
     player.Play();
    
           NSNotificationCenter.DefaultCenter.AddObserver(
            AVAudioSession.InterruptionNotification, (notification) =>
            {
               var okAlertController = UIAlertController.Create("Title", "The message", UIAlertControllerStyle.Alert);
                okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
               // Present Alert for testing           UIApplication.SharedApplication.Delegate.GetWindow().RootViewController.PresentViewController(okAlertController, true, null);
           });
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful