简体   繁体   English

如何在 iOS 10 上使用 CallKit 显示来电显示(添加标识条目)

[英]How to display caller id (add identification entry) using CallKit on iOS 10

I have created a basic Call Directory Extension in Xcode.我在 Xcode 中创建了一个基本的呼叫目录扩展。 The sample code that comes with it shows how to either block a phone number or display information about a phone number.它附带的示例代码显示了如何阻止电话号码或显示有关电话号码的信息。 Here is the bare minimum of code required to block phone number 22334455:这是阻止电话号码 22334455 所需的最少代码:

class CallDirectoryHandler: CXCallDirectoryProvider {

    override func beginRequest(with context: CXCallDirectoryExtensionContext) {
        context.delegate = self

        context.addBlockingEntry(withNextSequentialPhoneNumber: 22334455)
        //context.addIdentificationEntry(withNextSequentialPhoneNumber: 22334455, label: "Telemarketer")

        context.completeRequest()
    }
}

extension CallDirectoryHandler: CXCallDirectoryExtensionContextDelegate {
    func requestFailed(for extensionContext: CXCallDirectoryExtensionContext, withError error: Error) { }
}

According to the sample in Xcode, it should be just as easy to display caller id by using method addIdentificationEntry instead of addBlockingEntry, but I cannot get it to work.根据 Xcode 中的示例,通过使用方法 addIdentificationEntry 而不是 addBlockingEntry 来显示呼叫者 ID 应该同样容易,但我无法让它工作。

Blocking works fine, but if I try to display caller id instead, the phone just displays the phone number.阻止工作正常,但如果我尝试显示来电显示,电话只会显示电话号码。 It does not show the text "Telemarketer" that I try to add.它没有显示我尝试添加的文本“电话推销员”。

What am I missing?我错过了什么?

The answer was frustratingly simple.答案简单得令人沮丧。

addIdentificationEntry() requires the country code, addBlockingEntry() does not. addIdentificationEntry() 需要国家代码,addBlockingEntry() 不需要。

When I added 47 (Norway's country code) to the beginning of the phone number, it worked.当我在电话号码的开头添加 47(挪威的国家代码)时,它起作用了。 Here is the working code to display caller id for Norwegian phone number 22334455 (+4722334455):这是显示挪威电话号码 22334455 (+4722334455) 的来电显示的工作代码:

class CallDirectoryHandler: CXCallDirectoryProvider {

  override func beginRequest(with context: CXCallDirectoryExtensionContext) {
    context.delegate = self

    context.addIdentificationEntry(withNextSequentialPhoneNumber: 4722334455, label: "Telemarketer")

    context.completeRequest()
  }
}

addBlockingEntry() works with both 22334455 and 4722334455 as input. addBlockingEntry() 使用 22334455 和 4722334455 作为输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM