简体   繁体   English

Xamarin表格电话无法在iOS上使用

[英]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!! 它可以在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"));
    }

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. 您应该在本机级别上使用Dependency Services,因为预执行的程度很高且易于管理本机API。 Please check the below Implementation it will help you. 请检查以下实施,它将为您提供帮助。

Create the interface in your PCL Project- 在PCL专案中建立介面-

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

Create class in your IOS Native Project- 在您的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- 在您的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 在PCL项目中调用依赖服务ViewModel / View

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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