Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CarPlay blocks the NotificationBanner #421

Open
Anf139 opened this issue Dec 15, 2023 · 0 comments
Open

CarPlay blocks the NotificationBanner #421

Anf139 opened this issue Dec 15, 2023 · 0 comments

Comments

@Anf139
Copy link

Anf139 commented Dec 15, 2023

I have the iOS application with CarPlay support. I don't see the NotificationBanner during CarPlay on the iPhone's display or CarPlay's display.

Because of bannerPositionFrame is nil here:

func show(
        placeOnQueue: Bool,
        queuePosition: QueuePosition = .back,
        bannerPosition: BannerPosition = .top
    )

guard bannerPositionFrame != nil else {
    remove();
    return
}

I investigated a little bit and found the next call stack where appWindow is nil:

internal func updateBannerPositionFrames() {
    guard let window = appWindow else { return }
    bannerPositionFrame = BannerPositionFrame(
/// 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 || $0.activationState == .foregroundInactive }
            .map { $0 as? UIWindowScene }
            .flatMap { $0?.windows.first } ?? UIApplication.shared.delegate?.window ?? UIApplication.shared.keyWindow
    }

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

During CarPlay usage the connectedScenes can contain

<CPTemplateApplicationScene: 0x10a556f50; role: CPTemplateApplicationSceneSessionRoleApplication; activationState: UISceneActivationStateForegroundActive>
<UIWindowScene: 0x10a434c40; role: UIWindowSceneSessionRoleApplication; activationState: UISceneActivationStateForegroundActive>

I propose to use something like this:

var appWindow: UIWindow? {
    let scenes: [UIScene] = Array(UIApplication.shared.connectedScenes)
    let windowScenes: [UIWindowScene] = scenes.compactMap { $0 as? UIWindowScene } // avoid CarPlay CPTemplateApplicationScene
    let foregroundScene: UIWindowScene? = windowScenes.first { $0.activationState == .foregroundActive || $0.activationState == .foregroundInactive }
    return foregroundScene?.windows.first
}

To avoid usage of type CPTemplateApplicationScene which cannot be converted to UIWindowScene.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant