LoginSignup
13
11

More than 3 years have passed since last update.

Xcode11で作成したプロジェクトを古いOSに対応させる(とりあえず版)

Last updated at Posted at 2019-06-22

Xcode11 beta で新規プロジェクトを作成。
001.png

Deployment Targetを古いOSに設定すると、
0002.jpg

エラーがぞろぞろ出てくるのをなんとかしようという話。
004.png


1. AppDelegate.swift と SceneDelegate.swift
エラーが出ている箇所に@availableを付ける。

AppDelegate.swift
// MARK: UISceneSession Lifecycle

@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  ()
}

@available(iOS 13.0, *)
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  ()
}
SceneDelegate.swift
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

2. AppDelegateにwindowプロパティを追加する。

AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow? // 追加

とりあえず、これでエラーは出なくなります。

ただし、
(iOS 13)
1. 起動
2. AppDelegate application:didFinishLaunchingWithOptions: (windowはnil)
3. SceneDelegate scene:willConnectTo:options (windowに値がセットされる)

(iOS 12以下)
1. 起動
2. AppDelegate application:didFinishLaunchingWithOptions: (windowに値がセットされる)
3. SceneDelegate 呼ばれない

このような起動時の流れになりますので、windowプロパティにget / setしている場合はもうひと工夫必要になります。

Xcode11で作成したプロジェクトを古いOSに対応させる 完結編


Xcode 11 beta3を元に作成しています。後日変更される可能性があります。

13
11
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
13
11