Xamarin Forms UWP Missing Phone Call Manager 程序集

Xamarin Forms UWP Missing Phone Call Manager Assembly

问题

正在学习 Xamarin 大学课程 XAM120。在将我的 IDial 实现添加到我的 UWP 项目时遇到障碍。出于某种原因,我的项目没有在我的系统上获取 PhoneCallManager API。

错误:

Error CS1069
The type name 'PhoneCallManager' could not be found in the namespace 'Windows.ApplicationModel.Calls'. This type has been forwarded to assembly 'Windows.Foundation.UniversalApiContract, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime' Consider adding a reference to that assembly.

代码:

using System.Threading.Tasks;
using Windows.Foundation.Metadata;
using Phoneword.UWP;
using Xamarin.Forms;

namespace Phoneword.UWP
{
    public class PhoneDialer : IDialer
    {
        public Task<bool> DialAsync(string phoneNumber)
        {
            if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.Calls.CallsPhoneContract", 1, 0))
            {
                Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI(phoneNumber, "Phoneword");
                return Task.FromResult(true);
            }

            return Task.FromResult(false);
        }
    }
}

要使依赖注入在 Xamarin 中工作,您需要告诉它将您的 class 与正确的接口耦合!

因此在您的 命名空间 Phoneword.UWP 行上方

[assembly: Xamarin.Forms.Dependency (typeof (PhoneDialer))]

查看文档中的教程:https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/introduction/#Registration

不要忘记在 UWP 中启用 Phone 拨号器功能。

将以下引用添加到您的 UWP 项目: