-3

I am new for Xamarin and I just wanted to directly make a phone call from my Xamarin app. I just wanted to include the hashtag(#) symbol in the phone number as a string, but it doesn't include the symbol when the program is executed.

Here is the code,

private void Button_Clicked(object sender, EventArgs e)
        {
            var phoneDialer = CrossMessaging.Current.PhoneDialer;
            if (phoneDialer.CanMakePhoneCall)
                phoneDialer.MakePhoneCall("*999#");
        }

Any help would be appreciated!

1 Answers1

0

Have a look at this thread:

Specifically, if a URL contains the * or # characters, the Phone application does not attempt to dial the corresponding phone number.

There is also an answer in Swift which says iOS11 now allows us to call number with * or # , I translate it to C# and you can have a try with dependency service:

In shared Project:

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
        DependencyService.Get<IPhoneCallTask>().DoPhoneCall();
    }
}

public interface IPhoneCallTask
{
    void DoPhoneCall();
}

In iOS Project:

[assembly: Dependency(typeof(phoneCall))]
namespace App591.iOS
{
    class phoneCall : IPhoneCallTask
    {
        public void DoPhoneCall()
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                NSString number = new NSString("*111*12345#");

                NSString encode = number.CreateStringByAddingPercentEncoding(NSUrlUtilities_NSCharacterSet.UrlHostAllowedCharacterSet);
                NSString header = new NSString("tel://");
                string tmp = string.Format("{0}{1}", encode, header);
                NSString urlTemp = new NSString(tmp);

                if (UIApplication.SharedApplication.CanOpenUrl(new Uri(urlTemp)))
                {
                    UIApplication.SharedApplication.OpenUrl(new Uri(urlTemp));
                }
            }
        }
    }
}
nevermore
  • 15,432
  • 1
  • 12
  • 30