Skip to content

Instantly share code, notes, and snippets.

@dbonates
Last active April 5, 2022 23:31
Show Gist options
  • Save dbonates/eee09c22a876cb321599aef2600c6280 to your computer and use it in GitHub Desktop.
Save dbonates/eee09c22a876cb321599aef2600c6280 to your computer and use it in GitHub Desktop.
//
// WillianViewController.swift
// TempApp
//
// Created by Daniel Bonates on 05/04/22.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(appActive(_:)), name: UIApplication.didBecomeActiveNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(appWillBeInactive(_:)), name: UIApplication.willResignActiveNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(goneBg(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(backToFront(_:)), name: UIApplication.willEnterForegroundNotification, object: nil)
}
@objc func appActive(_ sender: NSNotification) {
print("👻 app foi ativada pelo iOS")
}
@objc func appWillBeInactive(_ sender: NSNotification) {
print("👻 app vai passar pra inativa")
}
@objc func goneBg(_ sender: NSNotification) {
print("👻 app foi pra background")
}
@objc func backToFront(_ sender: NSNotification) {
print("👻 app voltou pra tela")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment