LoginSignup
1
3

More than 3 years have passed since last update.

iOS 13 起動時/終了時メモ

Last updated at Posted at 2020-07-07

従来の処理ができない。

iOS13から次のメソッドが効かなくなったようです。 Xcodeから新規にプロジェクトを作成した時は注意。
・ applicationDidBecomeActive
・ applicationWillResignActive
・ applicationDidEnterBackground
・ applicationWillEnterForeground

代わりの処理を用意する

NotificationCenterを利用する。起動時/終了時のイベント名がUIScene系列で定義されているのでそれを利用する。

func application(_ application: UIApplication,
                    didFinishLaunchingWithOptions launchOptions: 
                    [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

    NotificationCenter.default.addObserver(self, 
         selector: #selector(appWillResignActive(_:)), 
         name: UIScene.willDeactivateNotification, object: nil)

    NotificationCenter.default.addObserver(self, 
        selector: #selector(appDidBecomeActive(_:)), 
        name: UIScene.didActivateNotification, object: nil)

    return true
}

呼び出すメソッドを定義。

@objc func appWillResignActive(_ application: UIApplication) {

}

@objc func appDidBecomeActive(_ application: UIApplication) {

}
1
3
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
1
3