CallKit 块编号通过 JSON API
CallKit Block Number through JSON API
我想阻止通过我的 JSON Api 向用户输入的号码。我将在 JSON API 中获取号码列表,并且我将在 Call Directory Extension 中使用我的 NSURLSession api 请求。有可能实现这一目标吗?
我正在阅读这篇文章 - https://www.raywenderlich.com/150015/callkit-tutorial-ios,他们在执行扩展程序时将一个数字添加为黑名单。
根据苹果文档,扩展将在系统收到任何来电时执行。那么我们能否有足够的时间触发 api 并阻止某些号码?或者在这种情况下我们可以使用应用程序组来共享数据库吗?
技术上是的,我们可以从我们的应用程序扩展中发出 URLSession
请求。来自 Apple 文档
An app extension can initiate uploads or downloads using an
NSURLSession object, with results of those operations, reported to the
containing app.
但是,它很有可能无法运行,因为后台任务可能 运行 需要更长的时间。在您的情况下触发请求并获得 JSON。再次来自 Apple documentation,标题为“某些 API 对应用程序扩展不可用”
Perform long-running background tasks The specifics of this limitation
vary by platform, as described in the extension point chapters in this
document.
因此,在您的情况下实现呼叫阻止的最佳方法是从包含应用程序的 phone 号码列表中下载并存储,并将其与您的呼叫目录分机共享。
这里要注意,你的 phone 数字列表应该是 Int64 的排序列表,否则你可能会出错。
的更多信息
您可以在override func beginRequest(with context: CXCallDirectoryExtensionContext)
方法的实现中使用addBlockingEntry(withNextSequentialPhoneNumber:)
方法。
class CustomCallDirectoryProvider: CXCallDirectoryProvider {
override func beginRequest(with context: CXCallDirectoryExtensionContext) {
let blockedPhoneNumbers: [CXCallDirectoryPhoneNumber] = [ … ]
for phoneNumber in blockedPhoneNumbers.sorted(by: <) {
context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber)
}
context.completeRequest()
}
}
The document 说:
Because this method is called only when the system launches the app extension and not for each individual call, you must specify call identification information all at once; you cannot, for example, make a request to a web service to find information about an incoming call.
我想它已经告诉你答案了
我想阻止通过我的 JSON Api 向用户输入的号码。我将在 JSON API 中获取号码列表,并且我将在 Call Directory Extension 中使用我的 NSURLSession api 请求。有可能实现这一目标吗? 我正在阅读这篇文章 - https://www.raywenderlich.com/150015/callkit-tutorial-ios,他们在执行扩展程序时将一个数字添加为黑名单。 根据苹果文档,扩展将在系统收到任何来电时执行。那么我们能否有足够的时间触发 api 并阻止某些号码?或者在这种情况下我们可以使用应用程序组来共享数据库吗?
技术上是的,我们可以从我们的应用程序扩展中发出 URLSession
请求。来自 Apple 文档
An app extension can initiate uploads or downloads using an NSURLSession object, with results of those operations, reported to the containing app.
但是,它很有可能无法运行,因为后台任务可能 运行 需要更长的时间。在您的情况下触发请求并获得 JSON。再次来自 Apple documentation,标题为“某些 API 对应用程序扩展不可用”
Perform long-running background tasks The specifics of this limitation vary by platform, as described in the extension point chapters in this document.
因此,在您的情况下实现呼叫阻止的最佳方法是从包含应用程序的 phone 号码列表中下载并存储,并将其与您的呼叫目录分机共享。
这里要注意,你的 phone 数字列表应该是 Int64 的排序列表,否则你可能会出错。
的更多信息
您可以在override func beginRequest(with context: CXCallDirectoryExtensionContext)
方法的实现中使用addBlockingEntry(withNextSequentialPhoneNumber:)
方法。
class CustomCallDirectoryProvider: CXCallDirectoryProvider {
override func beginRequest(with context: CXCallDirectoryExtensionContext) {
let blockedPhoneNumbers: [CXCallDirectoryPhoneNumber] = [ … ]
for phoneNumber in blockedPhoneNumbers.sorted(by: <) {
context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber)
}
context.completeRequest()
}
}
The document 说:
Because this method is called only when the system launches the app extension and not for each individual call, you must specify call identification information all at once; you cannot, for example, make a request to a web service to find information about an incoming call.
我想它已经告诉你答案了