Swift4.2 foreground、background オブザーバー
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver( self,
selector:#selector(background),
name: UIApplication.didEnterBackgroundNotification,object: nil)
NotificationCenter.default.addObserver( self, selector: #selector(foreground),name: UIApplication.willEnterForegroundNotification,object: nil)
}
@objc func background() { print("background") }
@objc func foreground() { print("foreground") }
}
参考箇所 スーパークラス