2017-07-18 39 views
0

问题Xamarin窗体UWP缺少的电话呼叫管理大会

通过Xamarin大学课程XAM120工作。在我的UWP项目中添加我的IDial实现时遇到了阻止程序。出于某种原因,我的项目没有在我的系统上获取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); 
     } 
    } 
} 

回答

2

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

enter image description here

1

依赖注入到Xamarin工作,你需要将它与正确的接口告诉夫妇类!

所以你上面的命名空间Phoneword.UWP线以下的地方

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

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

+0

'使用Xamarin.Forms; using System.Threading.Tasks;使用Windows.Foundation.Metadata的 ; using Phoneword.UWP; [assembly:Xamarin.Forms.Dependency(typeof(PhoneDialer))]'这里是我使用的列表和程序集引用,不幸的是我仍然看到同样的错误。 –

+0

您可以在问题中调整示例代码以反映您在项目中的含义吗?因为如果它是正确的,它会给出更好的概述。 – Depechie

1

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