アプリがバックグラウンド・フォアグラウンドになった時、ViewController内で処理を行いたい時のSwiftでの書き方について、サンプルコードで説明します。 AppDelegateでの検知と通知 バックグラウンド・フォアグラウンドの検知はAppDelegateの「applicationDidEnterBackground」と「applicationWillEnterForeground」のメソッドでそれぞれ実行できますが、ViewControllerで利用するにはNSNotificationCenterを使って通知を引き渡す必要があります。func applicationDidEnterBackground(application: UIApplication) { // Use this method to release shared resources, save user d