You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
open-im-sdk-flutter-m/ios/Classes/Module/BaseServiceManager.swift

50 lines
1.2 KiB

//
// BaseServiceManager.swift
// flutter_openim_sdk
//
// Created by willem on 2021/10/9.
//
import Flutter
import OpenIMCore
import UIKit
public typealias ImHandler = (_ methodCall: FlutterMethodCall, _ result: @escaping FlutterResult) -> Void
open class BaseServiceManager {
public let channel: FlutterMethodChannel
private var methodHandlers: [String: ImHandler] = [:]
public init(channel: FlutterMethodChannel) {
self.channel = channel
self.registerHandlers()
}
public func handleMethod(call: FlutterMethodCall, result: @escaping FlutterResult) {
let method: String = call.method
guard let handler = methodHandlers[method] else {
print("Handle MethodName Error: \(typeName(self))'s method: [\(method)] not found")
return
}
handler(call, result)
}
public subscript(_ key: String) -> ImHandler? {
get {
methodHandlers[key]
}
set {
methodHandlers[key] = newValue
}
}
public func registerHandlers() {
}
public func callBack(_ result: @escaping FlutterResult, _ content: Any? = nil) {
safeMainAsync {
result(content)
}
}
}