I create numbers array from CNContact in singleton. But when I reload my CallKit extensions CallKit doesn't block number that I blocked before. Number length is 11 characters. Array isn't null. After reload CallKit Extension there is no error.
static let shared = BlockNumbersManager()
private init() { }
open var blockNumbers: [CXCallDirectoryPhoneNumber] = []
open func getIntegerBlockNumbers() -> [CXCallDirectoryPhoneNumber] {
return blockNumbers
}
private func addBlockingPhoneNumbers(to context: CXCallDirectoryExtensionContext) throws {
let phoneNumbers: [CXCallDirectoryPhoneNumber] = BlockNumbersManager.shared.getIntegerBlockNumbers() // TODO: add numbers for block dynamically.
for phoneNumber in phoneNumbers {
context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber)
}
}
What have I missed?
Currently in iOS 10.x, every time your Call Directory extension runs it must provide a complete set of phone numbers to either block or identify with a label. In other words, if it runs once and adds blocked phone numbers
[A, B, C], and you wish to also block phone numberD, then the next time the extension is run it must provide the complete list[A, B, C, D].In iOS 11, some new APIs have been added which allow the extension to provide data incrementally whenever possible. For instance, if the extension has already run once and added blocked phone numbers
[A, B, C], and you wish to also block phone numberD, then the next time the extension is run it may first check if the system allows incremental loading, and if it does then it may add blocked numbers[D]and the full list of blocked numbers will become[A, B, C, D].Note that when using the new iOS 11 incremental loading APIs, your extension must always check whether incremental loading is currently allowed. The system may occasionally need to reload the complete list of phone numbers and your extension must remain able to provide the complete list.
See the documentation for these new APIs at https://developer.apple.com/documentation/callkit/cxcalldirectoryextensioncontext
In addition, you may view the 'Call Directory Extension' iOS extension template in Xcode 9 which has been updated to demonstrate the new incremental loading APIs: