简体   繁体   中英

How to calculate App Idle Time in MVVMCross Xamarin.iOS?

I am developing iOS Universal Application in Xamarin.iOS using MVVMCross. I want to calculate App Idle time I found the following useful help

iOS:Convert ObjC code to C#, How to know the time app has been idle

But there is an issue when i try to use this with MVVMCross which is that AppDelegate.cs in MvvmCross is inherited from MvxApplicationDelegate.cs

I am unable to override the following event in AppDelegate because it is not overriding UIApplication

public override void SendEvent (UIEvent uievent)
    {
        base.SendEvent (uievent);
        var allTouches = uievent.AllTouches;
        if (allTouches.Count > 0) {
            var phase = ((UITouch)allTouches.AnyObject).Phase;
            if (phase == UITouchPhase.Began || phase == UITouchPhase.Ended)
                ResetIdleTimer ();
        }
    }

You were close to the answer.

In a default MvvMCross project, there is a Main.cs , that contains a Application class.

You just have to replace the null in following line with your UIApplication's child class name

UIApplication.Main(args, null, "AppDelegate");

eg If your class name is MyApplication which is inherited from UIApplication then it should be like

UIApplication.Main(args, "MyApplication", "AppDelegate");

and add a class MyApplication

[Register("MyApplication")]
public class MyApplication : UIApplication
{
    public override void SendEvent(UIEvent uievent)
    {
        base.SendEvent(uievent);
        var allTouches = uievent.AllTouches;
        if (allTouches.Count > 0)
        {
            var phase = ((UITouch)allTouches.AnyObject).Phase;
            if (phase == UITouchPhase.Began || phase == UITouchPhase.Ended)
                ResetIdleTimer();
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM