gpt4 book ai didi

iOS CallKit 调用识别

转载 作者:行者123 更新时间:2023-11-30 11:41:35 27 4
gpt4 key购买 nike

我已成功安装扩展CXCallDirectoryProvider,以识别预先添加的电话条目。我在网上找到的文档相当不够。尽管如此,我还是成功地完成了必要的电话条目的初始导入。通过重写 func beginRequest(with context: 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并且工作起来就像一个魅力

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:)要请求重新运行扩展,后续重新运行应该是增量的。

关于iOS CallKit 调用识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49239456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com