Apple Message Filter Extension with Flutter不工作

snz8szmq  于 2023-05-08  发布在  Flutter
关注(0)|答案(1)|浏览(120)

我正在尝试在我的flutter bloc中使用iOS原生扩展。它是专门的消息过滤器扩展。我在XCode上实现了这个扩展,路径是> New > Target > This extension。我读了document。根据我阅读的与此问题相关的文档和答案,没有额外的配置。下面是我的扩展代码片段:

func handle(_ queryRequest: ILMessageFilterQueryRequest, context: ILMessageFilterExtensionContext, completion: @escaping (ILMessageFilterQueryResponse) -> Void) {
    // First, check whether to filter using offline data (if possible).
    print(">>>>> HANDLED SMS")
    let offlineAction = self.offlineAction(for: queryRequest)

    switch offlineAction {
    case .allow, .junk, .promotion, .transaction:
        // Based on offline data, we know this message should either be Allowed, Filtered as Junk, Promotional or Transactional. Send response immediately.
        let response = ILMessageFilterQueryResponse()
        response.action = offlineAction

        completion(response)

    case .none:
        // Based on offline data, we do not know whether this message should be Allowed or Filtered. Defer to network.
        // Note: Deferring requests to network requires the extension target's Info.plist to contain a key with a URL to use. See documentation for details.
        context.deferQueryRequestToNetwork() { (networkResponse, error) in
            let response = ILMessageFilterQueryResponse()
            response.action = .none

            if let networkResponse = networkResponse {
                // If we received a network response, parse it to determine an action to return in our response.
                response.action = self.action(for: networkResponse)
            } else {
                NSLog("Error deferring query request to network: \(String(describing: error))")
            }

            completion(response)
        }

    @unknown default:
        break
    }
}

private func offlineAction(for queryRequest: ILMessageFilterQueryRequest) -> ILMessageFilterAction {
    // Replace with logic to perform offline check whether to filter first (if possible).
    print("IOS MESSAGE EXTENSIONNNN!!!")
    return .none
}

private func action(for networkResponse: ILNetworkResponse) -> ILMessageFilterAction {
    // Replace with logic to parse the HTTP response and data payload of `networkResponse` to return an action.
    return .none
}

我还通过消息>未知和垃圾邮件激活了我的应用程序。我期待一个日志消息时,我的手机收到短信布没有日志消息。我错过了什么?我是否需要额外的Flutter配置?

zbq4xfa0

zbq4xfa01#

好吧,我实际上不是来自Flutter背景,但从我在原生iOS的经验,激活您的应用程序后,通过消息>未知&垃圾邮件,你需要运行您的消息过滤器扩展从Xcode在iPhone的消息应用程序
更详细的解释请参考我的回答Detail explanation

相关问题