c# - 如何使用 Xamarin 中的 CallDirectoryExtension 创建一个提供来电显示的应用程序?

标签 c# ios xamarin.ios callkit

我正在按照 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,但我无法让它工作。

我错过了什么?

最佳答案

答案简单得令人沮丧。

AddIdentificationEntry() 需要国家代码,AddBlockingEntry() 不需要。

当我在电话号码的开头添加 47(挪威的国家/地区代码)时,它起作用了。以下是显示挪威电话号码 22334455 来电显示的工作代码:

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

  cxContext.AddIdentificationEntry(4722334455, "Telemarketer");

  cxContext.CompleteRequest(null);
}

addBlockingEntry() 使用 22334455 和 4722334455 作为输入。

关于c# - 如何使用 Xamarin 中的 CallDirectoryExtension 创建一个提供来电显示的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39601275/

相关文章:

c# - ASP.NET C# : Call serverside function together with Jquery BlockUI

c# - 如何保护 VS 中的连接字符串?

c# - 在代码中创建时的 UITableView 工件

c# - HttpClient Gzip 压缩

c# - 如何访问 UI Spy 看不到的元素以使用 C# 自动化 win32 应用程序

ios - 找不到带有 Cocoapods 0.37、Swift、框架的 GoogleAnalytics-iOS-SDK 的 header

javascript - 在 keyup 函数运行时保持 iOS 键盘打开

iphone - ios5 上的自动释放替代方案

iphone - MonoTouch 自定义 UI 切换颜色

c# - 如何将 Objective-C initXXX 方法绑定(bind)到 Xamarin.iOS 的具有相同类型参数的构造函数?