There is an answer for obj-C: iOS takes action after a period of inactivity (no user interaction)
, , reset - . (, ) .
, .
-, UIApplication , :
public class Application
{
static void Main (string[] args)
{
UIApplication.Main (args, "Application", "AppDelegate");
}
}
[Register ("Application")]
public class UIApplicationWithTimeout : UIApplication
{
const int TimeoutInSeconds = 60;
NSTimer idleTimer;
public override void SendEvent (UIEvent uievent)
{
base.SendEvent (uievent);
if (idleTimer == null)
ResetTimer ();
var allTouches = uievent.AllTouches;
if (allTouches != null && allTouches.Count > 0 && ((UITouch)allTouches.First ()).Phase == UITouchPhase.Began)
ResetTimer ();
}
void ResetTimer ()
{
if (idleTimer != null)
idleTimer.Invalidate ();
idleTimer = NSTimer.CreateScheduledTimer (new TimeSpan (0, 0, TimeoutInSeconds), TimerExceeded);
}
void TimerExceeded ()
{
NSNotificationCenter.DefaultCenter.PostNotificationName ("timeoutNotification", null);
}
}
(caveat: ), ( "timeoutNotification" ).
(, ViewController)
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
testViewController viewController;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
viewController = new testViewController ();
window.RootViewController = viewController;
window.MakeKeyAndVisible ();
NSNotificationCenter.DefaultCenter.AddObserver ("timeoutNotification", ApplicationTimeout);
return true;
}
void ApplicationTimeout (NSNotification notification)
{
Console.WriteLine ("Timeout !!!");
}
}
@ , - , , , .