Session support in single point?

My banking domain based application requires session processing. When the application is inactive (without any touch events after opening the application), it is necessary to calculate the time in the background.

I handle session service when an application is brought into the foreground and onResignInactive events in AppDelegate.

I need to process the application when you live. Please help me figure this out.

+2
source share
2 answers

There is an answer for obj-C: iOS takes action after a period of inactivity (no user interaction)

, , reset - . (, ) .

, .

-, UIApplication , :

//Main.cs
public class Application
{
    static void Main (string[] args)
    {
        //Here I specify the UIApplication name ("Application") in addition to the AppDelegate
        UIApplication.Main (args, "Application", "AppDelegate");
    }
}

//UIApplicationWithTimeout.cs

//The name should match with the one defined in Main.cs
[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)

//AppDelegate.cs
[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 ();

        //Listen to notifications !
        NSNotificationCenter.DefaultCenter.AddObserver ("timeoutNotification", ApplicationTimeout);

        return true;
    }

    void ApplicationTimeout (NSNotification notification)
    {
        Console.WriteLine ("Timeout !!!");
        //push any viewcontroller
    }
}

@ , - , , , .

+1

-, , . - .

0

All Articles