I have a SceneDelegate class which is part of Target 1 code. Target 1 is compiled as a static library.
public class SceneDelegate: UIResponder, UIWindowSceneDelegate {
public var window: UIWindow?
// SceneDidBecomeActive
// other lifecycle events
}
The SceneDelegate is programmatically assigned in the 'configurationForConnecting' of the AppDelegate in Target 1. i.e.
config = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
// Set the scene delegate
config.delegateClass = SceneDelegate.self
Now, I do 'extension SceneDelegate' in Target 2. In this extension, I have put the 'willConnectTo' function definition. Target 2 is also compiled as a static library.
extension SceneDelegate {
public func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// ...
}
// Also has sceneDidDisconnect
}
The App Target has Target 1 and Target 2 added under 'Link Binary with Libraries'.
Now when the application runs, willConnectTo is never invoked, which was in Target 2. The other code in Target 2 is invoked properly. However the other lifecycle states like SceneDidBecomeActive, sceneDidResignActive etc from Target 1 gets invoked.
Is there any limitation as such when using extensions in this manner ?
config.delegateClass = SceneDelegate.self
for target 1, then that is where the scene delegate lifecycle events will be sent. ThewillConnectTo
is one of those so it needs to be in target 1. – Newmodel