Last active
February 21, 2018 01:04
-
-
Save zlq4863947/d852326a57c22d07a2c5f6021833ce2f to your computer and use it in GitHub Desktop.
【Swift4】ViewControllerでアプリがバックグラウンド/フォアグラウンドになったことを検知する方法 ref: https://qiita.com/zlq4863947/items/2484bcdd12c90db45b01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func applicationDidEnterBackground(_ application: UIApplication) { | |
// アプリがバックグラウンドへ移行するタイミングを通知 | |
NotificationCenter.default.post(name: Notification.Name.UIApplicationDidEnterBackground, object: nil) | |
} | |
func applicationWillEnterForeground(_ application: UIApplication) { | |
// アプリがフォアグラウンドへ移行するタイミングを通知 | |
NotificationCenter.default.post(name: Notification.Name.UIApplicationWillEnterForeground, object: nil) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AppDelegate -> applicationWillEnterForegroundの通知 | |
@objc func viewWillEnterForeground(notification: Notification) { | |
print("フォアグラウンド") | |
} | |
// AppDelegate -> applicationDidEnterBackgroundの通知 | |
@objc func viewDidEnterBackground(notification: Notification) { | |
print("バックグラウンド") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment