Hi all,
I'm working on a Call Directory Extension using CXCallDirectoryExtensionContext. I want to add a list of numbers to be blocked. Here's the function I use:
override func beginRequest(with context: CXCallDirectoryExtensionContext) {
context.delegate = self
let blockedNumbers = loadNumberEntries(forKey: blockedKey)
let identifiedNumbers = loadNumberEntries(forKey: identifiedKey)
addAllBlocking(blockedNumbers, to: context)
addAllIdentification(identifiedNumbers, to: context)
context.completeRequest()
}
private func addAllBlocking(_ entries: [NumberEntry], to context: CXCallDirectoryExtensionContext) {
let numbers: [Int64] = entries.compactMap {
Int64($0.countryCode + $0.phone)
}.sorted()
for number in numbers {
context.addBlockingEntry(withNextSequentialPhoneNumber: number)
print("# Added blocking entry: \(number)")
}
}
When I run this, I see in the console:
# Added blocking entry: (*my number with country code*)
So it seems the number is added correctly. However, in practice, the number is not blocked on the device.
I’ve made sure that:
-
The number is stored with the country code prefix.
-
The extension is enabled in Settings → Phone → Call Blocking & Identification.
-
The extension is reloaded after adding numbers.
-
The array of numbers is sorted in ascending order before calling addBlockingEntry.
Despite all this, the number still isn’t blocked.
Does anyone know why the print shows the number added, but it doesn’t actually block the call? Am I missing something in the way CXCallDirectoryExtensionContext works?
Thanks for any advice!