0

我正在按照 Xamarin 指南创建一个 iPhone 应用程序,该应用程序可以通过创建呼叫目录扩展来阻止电话号码或显示来电显示:

https://developer.xamarin.com/guides/ios/platform_features/introduction-to-ios10/callkit/#Implementing-a-Call-Directory-Extension

Xamarin 文档中的代码并未完全更新,但如果您只是在 Xamarin Studio for OS X 中创建一个呼叫目录扩展,您将获得一些示例代码来帮助您入门。

以下是阻止电话号码 22334455 的最简单代码:

[Register("CallDirectoryHandler")]
public class CallDirectoryHandler : CXCallDirectoryProvider, ICXCallDirectoryExtensionContextDelegate
{
    protected CallDirectoryHandler(IntPtr handle) : base(handle) { }

    public override void BeginRequestWithExtensionContext(NSExtensionContext context)
    {
        var cxContext = (CXCallDirectoryExtensionContext)context;
        cxContext.Delegate = this;

        cxContext.AddBlockingEntry(22334455);
        //cxContext.AddIdentificationEntry(22334455, "Telemarketer");

        cxContext.CompleteRequest(null);
    }

    public void RequestFailed(CXCallDirectoryExtensionContext extensionContext, NSError error) { }
}

从示例代码看来,显示相同号码的来电显示应该同样容易,只需使用方法 AddIdentificationEntry 而不是 AddBlockingEntry,但我无法让它工作。

我错过了什么?

4

1 回答 1

2

The answer was frustratingly simple.

AddIdentificationEntry() requires the country code, AddBlockingEntry() does not.

When I added 47 (Norway's country code) to the beginning of the phone number, it worked. Here is the working code to display caller id for Norwegian phone number 22334455:

public override void BeginRequestWithExtensionContext(NSExtensionContext context)
{
  var cxContext = (CXCallDirectoryExtensionContext)context;
  cxContext.Delegate = this;

  cxContext.AddIdentificationEntry(4722334455, "Telemarketer");

  cxContext.CompleteRequest(null);
}

addBlockingEntry() works with both 22334455 and 4722334455 as input.

于 2016-09-20T19:53:29.260 回答