[英]How to calculate App Idle Time in MVVMCross Xamarin.iOS?
I am developing iOS Universal Application in Xamarin.iOS using MVVMCross.我正在使用 MVMCross 在 Xamarin.iOS 中开发 iOS 通用应用程序。 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 iOS:将 ObjC 代码转换为 C#,如何知道 app 已经空闲的时间
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但是当我尝试将它与 MvvmCross 一起使用时存在一个问题,即 MvvmCross 中的 AppDelegate.cs 是从 MvxApplicationDelegate.cs 继承的
I am unable to override the following event in AppDelegate because it is not overriding UIApplication我无法覆盖 AppDelegate 中的以下事件,因为它没有覆盖 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.在默认的 MvvMCross 项目中,有一个Main.cs ,其中包含一个
Application
类。
You just have to replace the null in following line with your UIApplication's child class name您只需将以下行中的 null 替换为您的 UIApplication 的子类名称
UIApplication.Main(args, null, "AppDelegate");
eg If your class name is MyApplication which is inherited from UIApplication then it should be like例如,如果你的类名是从 UIApplication 继承的 MyApplication 那么它应该像
UIApplication.Main(args, "MyApplication", "AppDelegate");
and add a class MyApplication
并添加一个类
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();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.