【发布时间】:2020-11-24 18:28:24
【问题描述】:
我尝试连接 iPhone 来构建我的颤振项目,但是出现了这个错误:
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)
}
}
【问题讨论】:
-
AppDelegate继承自FlutterAppDelegate与FlutterAppLifeCycleProvider兼容,UNUserNotificationCenterDelegate兼容。所以你不应该需要演员:self as? UNUserNotificationCenterDelegate应该是self -
@Larme 太棒了,非常感谢!