-
Notifications
You must be signed in to change notification settings - Fork 3
/
AnalyticsEngine.cs
64 lines (56 loc) · 1.82 KB
/
AnalyticsEngine.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
using System.IO.IsolatedStorage;
using System.Windows;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Threading.Tasks;
namespace GoogleAnalytics
{
public sealed partial class AnalyticsEngine
{
const string Key_AppOptOut = "GoogleAnaltyics.AppOptOut";
bool? appOptOut;
public bool AppOptOut
{
get
{
if (appOptOut.HasValue) return appOptOut.Value;
return GetAppOptOut();
}
set
{
if (!appOptOut.HasValue) GetAppOptOut();
if (appOptOut.Value != value)
{
appOptOut = value;
NSUserDefaults.StandardUserDefaults.SetBool(value, Key_AppOptOut);
if (value) GAServiceManager.Current.Clear();
}
}
}
private bool GetAppOptOut()
{
if (NSUserDefaults.StandardUserDefaults.ValueForKey(new NSString(Key_AppOptOut)) != null)
{
appOptOut = NSUserDefaults.StandardUserDefaults.BoolForKey(Key_AppOptOut);
}
else
{
appOptOut = false;
}
return appOptOut.Value;
}
public Task<bool> RequestAppOptOutAsync()
{
var tcs = new TaskCompletionSource<bool>();
var alertView = new UIAlertView("Help Improve User Experience",
"Allow anonomous information to be collected to help improve this application?",
null, "Cancel", "Ok");
alertView.Clicked += (object _, UIButtonEventArgs eb) =>
{
tcs.SetResult(eb.ButtonIndex != alertView.CancelButtonIndex);
};
alertView.Show();
return tcs.Task;
}
}
}