2016-03-10 103 views
2

我正在使用MVVMCross在Xamarin.iOS中開發iOS Universal Application。我想計算應用我發現下面的有益的幫助如何計算MVVMCross Xamarin.iOS中的應用程序空閒時間?

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

但是有當我嘗試用MVVMCross這是 AppDelegate.cs在MvvmCross從MvxApplicationDelegate.cs繼承使用此問題的空閒時間

我無法在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(); 
     } 
    } 

回答

2

你是接近的答案。

在默認的MvvMCross項目中,有一個Main.cs,其中包含Application類。

你只需要更換空在下面與您的UIApplication的子類名行

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

例如,如果你的類名是從UIApplication的繼承MyApplication的話,應該是像

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

並且添加類別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(); 
     } 
    } 
} 
+0

因此,我們寫的FinishLaching mvvmcross AppDelegateClass的代碼,我們在其中設置我們的App開始 public override bool FinishedLaunching(UIApplication app,NSDictionary options) –

+0

您不會更改它。這個邏輯保持在它的位置 - 在AppDelegate中。 –

+0

是的,你似乎正確:)抱歉,負面答案。我來檢查一下 –

相關問題