I've tried to connect iPhone to build my flutter project, but this error occurs :
Conditional cast from 'AppDelegate' to 'UNUserNotificationCenterDelegate' always succeeds
I guess it might be related with local notifications, but have no idea why the error occurs and how to fix it.
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)
}
}
What @Larme mentioned in the comments is correct. There's no need for self (FlutterAppDelegate) to be casted since AppDelegate inherits the FlutterAppDelegate class. The code should be
UNUserNotificationCenter.current().delegate = self
If you're using flutter_local_notifications plugin, you can also try removing ?
as demonstrated in the sample provided in their docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With