Search code examples
iosswiftxcodecocoapods

Use of undeclared type 'UIWindowScene'


I am developing with Xcode.

An error appears at line 156 of BaseNotificationBanner.swift file of cocoapod.

BaseNotificationBanner.swift Line 156

.map { $0 as? UIWindowScene }

How can I fix it?

BaseNotificationBanner.swift

/// The main window of the application which banner views are placed on
private let appWindow: UIWindow? = {
    if #available(iOS 13.0, *) {
        return UIApplication.shared.connectedScenes
            .first { $0.activationState == .foregroundActive }
            .map { $0 as? UIWindowScene }
            .map { $0?.windows.first } ?? UIApplication.shared.delegate?.window ?? nil
    }

    return UIApplication.shared.delegate?.window ?? nil
}()

Solution

  • UIWindowScene is introduced in iOS 13, it seems like you are on older Xcode version, so you either have to update to Xcode 11 or specify an older version of NotificationBanner pod like so: -

    pod 'NotificationBannerSwift', '2.5.0'