Bjarte Aune Olsen
Bjarte Aune Olsen

Reputation: 3310

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

I have created a basic Call Directory Extension in 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:

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.

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?

Upvotes: 3

Views: 4796

Answers (1)

Bjarte Aune Olsen
Bjarte Aune Olsen

Reputation: 3310

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 (+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.

Upvotes: 2

Related Questions