0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[SwiftUI] SceneDelegate を消して ApplicationDelegate だけにする

Posted at

これはなに

iOS 13 環境で ReplayKit & UIScene の相性が悪いため、泣く泣く UISceneDelegate を消して UIApplicationDelegate だけにしたときのメモです。

ReplayKit & UIScene: Assertion when calling RPSystemBroadcastPickerView · Issue #438 · twilio/video-quickstart-ios

If you must use RPSystemBroadcastPickerView then you should consider not using UIScene, and going back to UIApplicationDelegate.

やったこと

SceneDelegate をバッサリ削除

Info.plist から UIApplicationSceneManifest をバッサリ削除します。

image.png

その後、SceneDelegate.swift も不要になるので削除します。(SceneDelegate でやっていたことがある場合は AppDelegate に移行する必要がある)

AppDelegate から UIHostingController経由で SwiftUI の View を開く

AppDelegate.swift を次のように書き換えます。

import UIKit
import SwiftUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        window = UIWindow(frame: UIScreen.main.bounds)
        window!.rootViewController = UIHostingController(rootView: ContentView)
        window!.makeKeyAndVisible()

        return true
    }
}

このとき、 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { のような UISceneSession Lifecycle が残っているとうまくアプリが動かないので注意です。

これで一応アプリが起動するようになりますが、動作を保証するものではありません。あくまで自己責任で!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?