创建框架时获取 AppDelegate 参考 swift

Getting AppDelegate reference while creating framework swift

我正在创建自定义框架。我需要对 AppDelegate 的引用来执行操作,例如获取 window 或其他一些代表。

示例代码:

static var safeArea: UIEdgeInsets {
    var padding: UIEdgeInsets = UIEdgeInsets.zero
    if #available(iOS 11.0, *) {
        if let b = appDel.window?.safeAreaInsets {
            padding = b
        }
    }
    return padding
}

我遇到的主要问题是我需要多个级别的 AppDelegate 参考。

如有任何帮助,我们将不胜感激。

以下评论的示例来源:)。在框架内创建一个 sampleManager。将框架导入 appdelegate 并将 SampleManager.shared.delegate 设置为 self 作为弱引用。

public class SampleManager {

    public static let shared = SampleManager()
    
    public weak var delegate: UIApplicationDelegate?
    
    func doWhateverYouWant() {
    
    }
}
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    private let dependencyManager = DependencyManager()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        SampleManager.shared.delegate = self
        
        startAppCoordinator()
        return true
    }
}