sparrowcode / AlertKit

Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.
https://sparrowcode.io/frameworks
MIT License
2.3k stars 130 forks source link

Xcode 13 beta 3: 'shared' is unavailable in application extensions for iOS #33

Closed gongzhang closed 2 years ago

gongzhang commented 2 years ago

Describe the bug The package won't compile in latest Xcode 13.0 beta 3 using SPM. It seems that the latest compiler requires us to mark present(...) as @available(iOSApplicationExtension, unavailable) explicitly since UIApplication.shared is unavailable in extension target. Even though we don't have any extension target.

// SPAlertView.swift

    open func present(duration: TimeInterval = SPAlertConfiguration.duration, haptic: SPAlertHaptic = .success, completion: (() -> Void)? = nil) {

        if self.presentWindow == nil {
            self.presentWindow = UIApplication.shared.keyWindow // <=== 👀 Error: 'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.... 'shared' has been explicitly marked unavailable here (UIKit.UIApplication)
        }

        guard let window = self.presentWindow else { return }

        window.addSubview(self)

        // Prepare for present
        // ...

To Reproduce

  1. Create a new iOS project in Xcode, and add SPAlert in Package Dependencies.
  2. Add SPAlert library to iOS target.
  3. Compile.

Expected behavior No error like in Xcode 12.

Smartphone (please complete the following information):

ivanvorobei commented 2 years ago

Thanks for it, in beta I think no way using key window. I going to check it and find any other solution. Soon let you know here.

Aurther-Nadeem commented 2 years ago

Having the same issue :(

ivanvorobei commented 2 years ago

Fixed in 3.3.0, please, update. If have any problem after update version, let me know please.