class ViewController: UIViewController {
@IBOutlet weak var message: UILabel!
@IBOutlet weak var myNotification: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.updateInterface(_:)), name: UIApplicationWillEnterForegroundNotification, object: nil)
}
func updateInterface (notification: NSNotification){
myNotification.text = "Back to background with notification"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
按下home键之后, myNotification的text永久的改为 "Back to background with notification"