CallKit |
addIdentificationPhoneNumbers
. phoneNumbers
labels
. phoneNumbers
, . labels
, Test number.private func addIdentificationPhoneNumbers(to context: CXCallDirectoryExtensionContext) throws {
let phoneNumbers: [CXCallDirectoryPhoneNumber] = [ 79214203692 ]
let labels = [ "Test number" ]
for (phoneNumber, label) in zip(phoneNumbers, labels) {
context.addIdentificationEntry(withNextSequentialPhoneNumber: phoneNumber, label: label)
}
}
typealias
Int64
. 7XXXXXXXXXX, (country calling code), . +7, 7.addIdentificationPhoneNumbers
.phoneNumbers
labels
.reloadExtension
, addIdentificationPhoneNumbers
. .addIdentificationPhoneNumbers
, . , Numbers must be provided in numerically ascending order.. . , , .let container = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.ru.touchin.TouchInApp")
URL
:guard let fileUrl = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.ru.touchin.TouchInApp")?
.appendingPathComponent("contacts") else { return }
let numbers = ["79214203692",
"79640982354",
"79982434663"]
let labels = [" ",
" ",
" "]
var string = ""
for (number, label) in zip(numbers, labels) {
string += "\(number),\(label)\n"
}
try? string.write(to: fileUrl, atomically: true, encoding: .utf8)
CXCallDirectoryManager.sharedInstance.reloadExtension(
withIdentifier: "ru.touchin.TouchInApp.TouchInCallExtension")
@IBAction func addContacts(_ sender: Any) {
let numbers = ["79214203692",
"79640982354",
"79982434663"]
let labels = [" ",
" ",
" "]
writeFileForCallDirectory(numbers: numbers, labels: labels)
}
private func writeFileForCallDirectory(numbers: [String], labels: [String]) {
guard let fileUrl = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.ru.touchin.TouchInApp")?
.appendingPathComponent("contacts") else { return }
var string = ""
for (number, label) in zip(numbers, labels) {
string += "\(number),\(label)\n"
}
try? string.write(to: fileUrl, atomically: true, encoding: .utf8)
CXCallDirectoryManager.sharedInstance.reloadExtension(
withIdentifier: "ru.touchin.TouchInApp.TouchInCallExtension")
}
LineReader
.LineReader
. .addIdentificationPhoneNumbers
:private func addIdentificationPhoneNumbers(to context: CXCallDirectoryExtensionContext) throws {
guard let fileUrl = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.ru.touchin.TouchInApp")?
.appendingPathComponent("contacts") else { return }
guard let reader = LineReader(path: fileUrl.path) else { return }
for line in reader {
autoreleasepool {
//
let line = line.trimmingCharacters(in: .whitespacesAndNewlines)
//
var components = line.components(separatedBy: ",")
// Int64
guard let phone = Int64(components[0]) else { return }
let name = components[1]
context.addIdentificationEntry(withNextSequentialPhoneNumber: phone, label: name)
}
}
}
autoreleasepool
. .addContacts
numbers
.