简体   繁体   中英

Xamarin forms phone call is not working on iOS

I have the following code, I'm trying to make a phone call. It is working on Android but not iOS!!

  private void Call_Clicked(object sender, EventArgs e)
    {
        //var phoneDialer = CrossMessaging.Current.PhoneDialer;
        //if (phoneDialer.CanMakePhoneCall)
        //    phoneDialer.MakePhoneCall("+9611578268");
        Device.OpenUri(new Uri("tel:738284739"));
    }

I tried both commented and uncommented code, both didn't work. Any suggestions?

You should use the Dependency Services on native level because preformation will be high and easy to mange the native API. Please check the below Implementation it will help you.

Create the interface in your PCL Project-

 public interface ICall
 {
   bool OpenCallAction(string phoneNumber);
 } 

Create class in your IOS Native Project-

public class ICallService : ICall
{
    public bool OpenCallAction(string phoneNumber)
    {
        var number = new Uri(String.Format("tel:{0}", phoneNumber));
        return UIApplication.SharedApplication.OpenUrl(number);
    }
 }

Create class in your Android Native Project-

public class ICallService : ICall
{

    public bool OpenCallAction(string phoneNumber)
    {
        var number = new Uri(String.Format("tel:{0}", phoneNumber));
        return true;
    }

Call Dependency Service ViewModel/View in PCL project

 DependencyService.Get<ICall>().OpenCallAction("738284739")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM