我有一个应用程序目标和一些静态库。由于某些原因,我将 SceneDelegate 从应用程序目标移至静态库之一。
在info.plist文件中,SceneDelegate设置为$(PRODUCT_MODULE_NAME).SceneDelegate(如下图)
<dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
</dict>
</array>
</dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
</dict>
</dict>
现在这不起作用,因为 SceneDelegate 不再位于应用程序目标中。我尝试了 TargetName.SceneDelegate 但这只是给了我以下错误并且屏幕是黑色的。
[SceneConfiguration] Encoded configuration for UIWindowSceneSessionRoleApplication contained a UISceneDelegate class named "(null)", but no class with that name could be found.
[SceneConfiguration] Info.plist configuration "(no name)" for UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName key, but could not load class with name "TargetName.SceneDelegate".
这个堆栈溢出 https://stackoverflow.com/questions/58618577/scene-delegate-class-couldnt-be-loaded-even-though-delegate-class-name-is-pro答案建议使用 $(SWIFT_MODULE_NAME).SceneDelegate 但这不起作用,因为 $(SWIFT_MODULE_NAME) 的默认值是应用程序目标,即 $(PRODUCT_MODULE_NAME)。
还有其他方法可以在 info.plist 文件中设置 SceneDelegate 吗?
有一种动态的方式来设置 SceneDelegate,使用应用程序(configureForConnecting:选项) https://developer.apple.com/documentation/uikit/uiapplicationdelegate/3197905-application方法,但 SceneDelegate 在具有 AppDelegate 的目标中可能无法访问(是的,AppDelegate 也被移动到不同的目标)。
那么,我还能如何在 info.plist 文件中设置 SceneDelegate 呢?