This is the story:
In main app: - Some numbers are fetched from my web-service. These numbers append to NSUserDefaults.
In Call directory Extension:
Retrieving from UserDefaults:
private func retrievePhoneNumbersToIdentifyAndLabels() -> (phoneNumbers: [CXCallDirectoryPhoneNumber], labels: [String]) { let defaults = UserDefaults.init(suiteName: GROUP_NAME) let phones = defaults?.array(forKey: "phoneArray") as! [CXCallDirectoryPhoneNumber] let names = defaults?.array(forKey: "nameArray") as! [String] return (phones,names) } }
And here is the Call Directory Extension's function:
private func addAllIdentificationPhoneNumbers(to context: CXCallDirectoryExtensionContext) {
let (phoneNumbers, labels) = retrievePhoneNumbersToIdentifyAndLabels()
print(phoneNumbers)
print(labels)
for (phoneNumber, label) in zip(phoneNumbers, labels) {
context.addIdentificationEntry(withNextSequentialPhoneNumber: phoneNumber, label: label)
}
}
Problem: When I am trying to enable Call Blocking & Identification in Setting on my device, it gives "Error Enabling Extension" error. And also, in debugger of Xcode,
[User Defaults] Couldn't read values in CFPrefsPlistSource<0x10fe251d0> (Domain: GROUP_NAME, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
But here is the interesting parts of the story:
After these problems, somehow, print functions which in above function are running correctly. I mean, it can save phone numbers and labels to UserDefaults and also it can read from UserDefaults. To be clarify, I can reach UserDefaults in my extension. There is no problem.
Note: Of course, app groups of both main app and Call Directory Extension have been set and phone numbers have correct typealias which is Int64. And also, phone numbers are sorted ascending.