【问题标题】:Xamarin Forms UWP Missing Phone Call Manager AssemblyXamarin 形成 UWP 缺少电话呼叫管理器程序集
【发布时间】:2017-12-22 18:40:45
【问题描述】:

问题

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

错误:

错误 CS1069
在命名空间“Windows.ApplicationModel.Calls”中找不到类型名称“PhoneCallManager”。此类型已转发到程序集“Windows.Foundation.UniversalApiContract, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime” 考虑添加对该程序集的引用。

代码:

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);
        }
    }
}

【问题讨论】:

    标签: c# xamarin xamarin.forms window xamarin.uwp


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        所以在您的 namespace Phoneword.UWP 行上方放置以下

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

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

        【讨论】:

        • using Xamarin.Forms; using System.Threading.Tasks; using Windows.Foundation.Metadata; using Phoneword.UWP; [assembly: Xamarin.Forms.Dependency(typeof(PhoneDialer))] 这是我的使用列表和程序集参考,不幸的是我仍然看到同样的错误。
        • 您能否调整问题中的示例代码以反映您在项目中的内容?因为这将提供一个更好的概览,无论它是否正确。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-06
        • 2012-12-04
        • 1970-01-01
        • 1970-01-01
        • 2019-09-01
        相关资源
        最近更新 更多