Search code examples
iosswiftblockcallkitcaller-id

Is there a way to block No Caller ID with Call Directory Extension in iOS?


I am working on a custom Phone dialer app for iOS. My idea is to create a good experience by being able to block No Caller ID phone call with Call Directory Extension. Currently on iOS there is no way to block unknown caller, except by turning on Do Not Desturb mode.

Is there a way to somehow programmatically identify and block caller that has no phone number identification or by blocking a label that says No Caller ID?

So far I have tried this in CallDirectoryHandler

private func addAllBlockingPhoneNumbers(to context: CXCallDirectoryExtensionContext) {

    /**
     Retrieve all phone numbers to block from data store. For optimal performance and memory usage
     when there are many phone numbers, consider only loading a subset of numbers at a given time
     and using autorelease pool(s) to release objects allocated during each batch of numbers
     which are loaded.

     Numbers must be provided in numerically ascending order.
    */
    let unknownCaller = CXCallDirectoryPhoneNumber()
    let unknownCaller1: CXCallDirectoryPhoneNumber = 0
    let unknownCaller2: CXCallDirectoryPhoneNumber = 00000000
    let caller381X: CXCallDirectoryPhoneNumber = 38161XXXXXXX

    context.addBlockingEntry(withNextSequentialPhoneNumber: unknownCaller)
    context.addBlockingEntry(withNextSequentialPhoneNumber: unknownCaller1)
    context.addBlockingEntry(withNextSequentialPhoneNumber: unknownCaller2)
    context.addBlockingEntry(withNextSequentialPhoneNumber: caller38161X)
}

And so far I have been able to block this regular phone number 38161XXXXXXX but, if that same number calls by hiding with prefix #31#, the call will go through.

Does anyone know if this is possible and is there a way to identify and block No Caller ID?


Solution

  • No, a CallKit call blocking extension must specify the number(s) to be blocked. You cannot specify "no number" to be blocked.