从 iOS 上的消息过滤器扩展进行 API 调用

Make API call from message filter extension on iOS

我正在为 iOS 开发消息过滤器扩展,但有点卡住了。我想在扩展 class 内进行 API 调用,负责过滤收到的消息,但到目前为止它还没有工作。我可以在 ViewController class 中使用完全相同的代码,一切正常。
所以我的问题是:是否可以从消息过滤器扩展程序进行 API 调用? (如果是,我是否缺少某种特殊设置?)

根据 documentation 无法在扩展程序内进行任何网络调用,系统应处理它并为您与与您的应用关联的服务器通信

For privacy reasons, the system handles all communication with your associated server; your Message Filter app extension can't access the network directly.

Also for privacy reasons, your app extension can't write data to containers shared with the containing app.

因此,要调用您的服务器,您应该在 ILMessageFilterExtensionContext 实例

上调用 deferQueryRequestToNetwork(completion:)

If your app extension can't make this determination by itself, it tells Messages to send the information about the message to a server associated with your app. Your server examines the message information and sends a response to Messages, which passes the response to your app extension.