[英]iOS CallKit Call Identification
我已经成功安装了扩展名CXCallDirectoryProvider ,以便标识预先添加的电话条目。 我在网上找到的文档还不够。 不过,我已经设法达到了我最初导入必要电话条目的目的。 通过重写func beginRequest(具有上下文:CXCallDirectoryExtensionContext) 。 更加具体:
override func beginRequest(with context: CXCallDirectoryExtensionContext) {
context.delegate = self
// Check whether this is an "incremental" data request. If so, only provide the set of phone number blocking
// and identification entries which have been added or removed since the last time this extension's data was loaded.
// But the extension must still be prepared to provide the full set of data at any time, so add all blocking
// and identification phone numbers if the request is not incremental.
if #available(iOS 11, *) {
if context.isIncremental {
addOrRemoveIncrementalBlockingPhoneNumbers(to: context)
addOrRemoveIncrementalIdentificationPhoneNumbers(to: context)
} else {
addAllBlockingPhoneNumbers(to: context)
addAllIdentificationPhoneNumbers(to: context)
}
} else {
addAllBlockingPhoneNumbers(to: context)
addAllIdentificationPhoneNumbers(to: context)
}
context.completeRequest()
}
最初用于安装电话记录的被调用函数为addAllIdentificationPhoneNumbers ,其工作方式类似于charm 。
private func addAllIdentificationPhoneNumbers(to context: CXCallDirectoryExtensionContext) {
// Retrieve phone numbers to identify and their identification labels 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.
var allNumbers = [(Number: String, Fullname: String)]()
// load allNumbers from local db
// ...
// ...
// ...
var test = allNumbers.map { s -> (Number: CXCallDirectoryPhoneNumber, Fullname:String) in
(CXCallDirectoryPhoneNumber(s.Number)!, s.Fullname)
}
// inc order
test.sort(by: { $0.Number < $1.Number })
// do the mapping to satisfy CallKit
let allPhoneNumbers = test.map { $0.Number }
let labels = test.map { $0.Fullname }
for (phoneNumber, label) in zip(allPhoneNumbers, labels) {
context.addIdentificationEntry(withNextSequentialPhoneNumber: phoneNumber, label: label)
}
}
上面的代码在用户到达“设置”->“电话”->“呼叫阻止和识别”并在应用名称旁边启用句柄时运行。
现在问题部分...
该代码如何阻止
if context.isIncremental {
addOrRemoveIncrementalBlockingPhoneNumbers(to: context)
addOrRemoveIncrementalIdentificationPhoneNumbers(to: context)
}
被触发以便更新经常更改的记录?
是否有任何准则/模式或几乎所有其他内容可以指导我关于如何维护这些条目并在它们进行更改时保持最新,添加或删除过时的正确方法。 我无法在线找到有关增量的任何内容,仅用于初始addAllIdentificationPhoneNumbers即可 。
仅当您的扩展程序运行一次并提供了其初始的完整基准数据集后,才会请求增量数据集。
例如,如果扩展在安装后运行一次,提供其基准数据集,然后您的应用程序调用CXCallDirectoryManager.reloadExtension(identifier:completion:)
要求重新运行扩展,则后续的重新运行应是增量的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.