我有以下代码,我正在尝试拨打电话。它可以在Android上运行,但不能在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"));
    }


我尝试了注释和未注释的代码,都没有用。有什么建议么?

最佳答案

您应该在本机级别上使用Dependency Services,因为预执行的程度很高且易于管理本机API。请检查以下实施,它将为您提供帮助。

在PCL专案中建立介面-

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


在您的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);
    }
 }


在您的Android Native Project中创建类-

public class ICallService : ICall
{

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


在PCL项目中调用依赖服务ViewModel / View

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

关于ios - Xamarin表格电话无法在iOS上使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53613490/

10-11 09:15
查看更多