-
Notifications
You must be signed in to change notification settings - Fork 14
/
AppDelegate.cs
72 lines (57 loc) · 2.15 KB
/
AppDelegate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace TestApp.iOS
{
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
var allGesturesRecognizer = new AllGesturesRecognizer(delegate
{
SessionManager.Instance.ExtendSession();
});
var result = base.FinishedLaunching(app, options);
this.Window.AddGestureRecognizer(allGesturesRecognizer);
return result;
}
// Use this to display a white frame when the app is in background
public override void OnResignActivation(UIApplication uiApplication)
{
var view = new UIView(uiApplication.KeyWindow.Frame)
{
BackgroundColor = UIColor.Green,
Tag = new nint(101)
};
uiApplication.KeyWindow.AddSubview(view);
uiApplication.KeyWindow.BringSubviewToFront(view);
}
// when coming back from background, make sure the white frame is removed
public override void OnActivated(UIApplication uiApplication)
{
var view = uiApplication.KeyWindow.ViewWithTag(new nint(101));
view?.RemoveFromSuperview();
base.OnActivated(uiApplication);
}
class AllGesturesRecognizer : UIGestureRecognizer
{
public delegate void OnTouchesEnded();
private OnTouchesEnded touchesEndedDelegate;
public AllGesturesRecognizer(OnTouchesEnded touchesEnded)
{
this.touchesEndedDelegate = touchesEnded;
}
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
this.State = UIGestureRecognizerState.Failed;
this.touchesEndedDelegate();
base.TouchesEnded(touches, evt);
}
}
}
}