我尝试连接 iPhone 来构建我的 flutter 项目,但发生此错误:
Conditional cast from 'AppDelegate' to 'UNUserNotificationCenterDelegate' always succeeds
我猜它可能与本地通知有关,但不知道为什么会发生错误以及如何修复它。
AppDelegate.swift
import UIKit
import Flutter
import UserNotifications
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Run Code Online (Sandbox Code Playgroud)
@Larme 在评论中提到的是正确的。由于 AppDelegate 继承了 FlutterAppDelegate 类,因此不需要对 self (FlutterAppDelegate) 进行强制转换。代码应该是
UNUserNotificationCenter.current().delegate = self
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 flutter_local_notifications 插件,您还可以尝试删除,?如其文档中提供的示例所示。
| 归档时间: |
|
| 查看次数: |
1597 次 |
| 最近记录: |