【发布时间】:2022-07-24 19:45:34
【问题描述】:
我正在使用awesome_notifications 库,例如,为了防止 MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) 它在 AppDelegate 中使用: p>
SwiftAwesomeNotificationsPlugin.setPluginRegistrantCallback { registry in
SwiftAwesomeNotificationsPlugin.register(
with: registry.registrar(forPlugin: "io.flutter.plugins.awesomenotifications.AwesomeNotificationsPlugin")!)
FLTSharedPreferencesPlugin.register(
with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")!)
}
但我的自定义频道仍有错误: 未处理的异常:MissingPluginException(在通道 it.example.watch 上找不到方法 flutterToWatch 的实现) 而且我不知道如何像 awesome_notifications 那样在后台注册它。
我的频道:
private func initFlutterChannel() {
if let controller = window?.rootViewController as? FlutterViewController {
let channel = FlutterMethodChannel(
name: "it.example.watch",
binaryMessenger: controller.binaryMessenger)
channel.setMethodCallHandler({ [weak self] (
call: FlutterMethodCall,
result: @escaping FlutterResult) -> Void in
switch call.method {
case "flutterToWatch":
guard let watchSession = self?.session, watchSession.isPaired, watchSession.isReachable, let methodData = call.arguments as? [String: Any], let method = methodData["method"], let data = methodData["data"] else {
result(false)
return
}
let watchData: [String: Any] = ["method": method, "data": data]
// Pass the receiving message to Apple Watch
watchSession.sendMessage(watchData, replyHandler: nil, errorHandler: nil)
result(true)
default:
result(FlutterMethodNotImplemented)
}
})
}
}
【问题讨论】:
标签: flutter