LoginSignup
9
8

More than 5 years have passed since last update.

バックグラウンドから戻る際にアプリを初期化する

Last updated at Posted at 2016-10-27

最初に書いたやり方だと、アプリからホーム画面に行ってアプリに戻るとリセットされませんでした。

今は以下のようにしています。今のところよく動いています。

AppDelegate.swift
    ...
    func applicationWillEnterForeground(application: UIApplication) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        storyboard.instantiateViewControllerWithIdentifier("MainViewController")
    }
    ...

"MainViewController"にはInitial View Controllerを入れて下さい。これでフォアグラウンドに出るたびにアプリ全体が初期化されます。

最初に書いたやり方

Info.plistに以下の項目を追加する

Application does not run in background: YES

アプリがおかしくなったときにユーザーがリセットすることができる。アプリがまだ不安定なときに使える。

9
8
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
9
8