0

Suppose App is in foreground and user does not interact with app for 5 min, App should give alert. Suppose App is in background and it remain in background for more than 5 min App should give alert as soon as app comes in foreground.

Is there any standard way to do that?

New iOS Dev
  • 1,937
  • 7
  • 33
  • 67
  • Consider the below link for user inactivity: http://stackoverflow.com/questions/27621049/how-do-i-detect-user-inactivity-in-swift and in func applicationDidEnterBackground() you can check your condition. – Bhagyalaxmi Poojary Mar 08 '16 at 06:49
  • @BhagyalaxmiPoojary the answers on that link are not clear and specific, is there any other clear way? –  Mar 08 '16 at 06:57
  • Check this - http://stackoverflow.com/questions/26001574/how-to-detect-user-inactivity-since-last-touch-on-a-particular-viewcontroller-in – Bhagyalaxmi Poojary Mar 08 '16 at 06:58
  • Here is another - http://stackoverflow.com/questions/26001574/how-to-detect-user-inactivity-since-last-touch-on-a-particular-viewcontroller-in – Bhagyalaxmi Poojary Mar 08 '16 at 06:58
  • @BhagyalaxmiPoojary Thank You, but above link i only for one viewcomtroller also it can not handle my 2nd scenario when app is in backround – New iOS Dev Mar 08 '16 at 09:20

1 Answers1

0

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.

J.Wang
  • 1,136
  • 6
  • 12