2017-07-18 78 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電話撥號功能。