For the background part, basically you want to have a Counter
. This Counter
should do
- Observe
UIApplicationWillResignActiveNotification
notification. And record the time when the selector is called. Let's say it's lastActiveTime
.
- Observe
UIApplicationDidBecomeActiveNotification
notification. And inside the selector, compare the current time with lastActiveTime
. If it's more than 5 minutes, you'll pop up the alert.
For foreground, you could use some assumptions such as if the top most view controller is the same, assume the user hasn't interacted with the app. You can have a timer that keep checking the top most view controller.