7

(为了阻止善意的建议,是的,我上周在 Facebook 的开发者论坛上发布了这个问题。还没有回复。)

TL;博士

Facebook SDK 5.8 在启动时抱怨FBSDKLog: Unable to find a valid UIWindow

主要故事

在从头开始的单视图 Xcode 11/iOS 13 项目中,不再有与​​应用程序关联的默认UIWindow 成员。(窗口本身仍然存在;您可以UIWindowScene使用 Xcode 中的 View Hierarchy Debugger 或 Reveal 应用程序看到它,包含在 a 中。)

FBSDK 5.8 似乎确实支持 iOS-13,并四处寻找。相关代码在第 498 行

https://github.com/facebook/facebook-ios-sdk/blob/master/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKInternalUtility.m

Facebook 的代码遍历应用程序的connectedScenes成员,对我来说这是一个空集。如何修改我的代码以便 FBSDK 找到窗口?

一些黑客行为

我尝试添加以下内容,scene(_:willConnectTo:options:)但似乎为时已晚 - 那时 FBSDKLog 消息已经出现。(所以我在挥舞......)

guard let s = (scene as? UIWindowScene) else { return }
self.window = UIWindow(windowScene: s)

以下也失败了,但这只是在黑暗中的一个镜头:

guard let s = (scene as? UIWindowScene) else { return }
self.window = UIWindow(frame: s.coordinateSpace.bounds)
self.window?.windowScene = s
self.window?.rootViewController = ViewController(nibName: nil, bundle: nil)
self.window?.makeKeyAndVisible()
4

2 回答 2

1

如果您不使用新行为并且不介意恢复到旧方式,您可以尝试以下操作

  1. 删除Application Scene Manifest密钥Info.plist

    删除键

  2. 删除SceneDelegate.swift

  3. 添加var window: UIWindow?AppDelegate.swift

    import UIKit
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow? // <-- Here
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    
    //        window!.makeKeyAndVisible()
    
    
        return true
        }
    
    }
    
于 2020-03-05T00:48:52.173 回答
0
  1. window变量添加到AppDelegate
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
  2. UIWindow在里面赋值didFinishLaunchingWithOptions
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
         window = UIWindow(frame: UIScreen.main.bounds)
         if let window = window {
             window.makeKeyAndVisible()
             self.window = window
         }
    
         ApplicationDelegate.shared.application(
              application,
              didFinishLaunchingWithOptions: launchOptions
         )
    
         return true
     }
    
于 2020-08-18T13:30:31.367 回答