This project describes how to detect when a user presses the home button to leave your application and when they press the lock button to put your app into the background.
It utilizes CSNotificationCenter to detect Darwin notifications.
credit goes out to wqq on stackoverflow