-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPushSettingsViewController.xaml.cs
More file actions
198 lines (175 loc) · 5.61 KB
/
PushSettingsViewController.xaml.cs
File metadata and controls
198 lines (175 loc) · 5.61 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using AirshipDotNet;
using AirshipDotNet.Analytics;
namespace MauiSample;
public partial class PushSettingsViewController : ContentPage
{
public PushSettingsViewController()
{
InitializeComponent();
}
protected override async void OnAppearing()
{
base.OnAppearing();
enabledPushSwitch.On = AirshipDotNet.Airship.Push.UserNotificationsEnabled;
try
{
// Get channel ID asynchronously
var id = await AirshipDotNet.Airship.Channel.GetChannelId();
channelId.Detail = id ?? "";
}
catch (Exception ex)
{
Console.WriteLine($"Error getting channel ID: {ex.Message}");
channelId.Detail = "";
}
UpdateNamedUser();
UpdateTagsCell();
}
void displayFeatures(object sender, EventArgs e)
{
Navigation.PushAsync(new FeaturesViewController());
}
void enablePush_OnChanged(object sender, EventArgs e)
{
AirshipDotNet.Airship.Push.UserNotificationsEnabled = enabledPushSwitch.On;
}
async void CopyChannelID(object sender, EventArgs e)
{
try
{
var id = await AirshipDotNet.Airship.Channel.GetChannelId();
if (!string.IsNullOrEmpty(id))
{
await Clipboard.Default.SetTextAsync(id);
await DisplayAlert("Alert", "Channel ID copied to clipboard!", "OK");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error copying channel ID: {ex.Message}");
await DisplayAlert("Error", "Failed to copy channel ID", "OK");
}
}
void AddTag(object sender, EventArgs e)
{
string tagToAdd = tagLabel.Text;
AirshipDotNet.Airship.Channel.EditTags()
.AddTags(new string[] { tagToAdd })
.Apply();
UpdateTagsCell();
}
async void UpdateTagsCell()
{
tagLabel.Text = "";
try
{
var tags = await AirshipDotNet.Airship.Channel.GetTags();
string str = "";
foreach (string tag in tags)
{
str = str + tag + "\n";
}
tagsList.Text = str;
}
catch (Exception ex)
{
Console.WriteLine($"Error updating tags: {ex.Message}");
tagsList.Text = "Error loading tags";
}
}
// ==================== Analytics Tests ====================
async void OnTrackEventClicked(object sender, EventArgs e)
{
try
{
var customEvent = new CustomEvent("test_event")
{
EventValue = 123.45,
TransactionId = "txn_" + DateTime.Now.Ticks
};
customEvent.AddProperty("test_string", "hello");
customEvent.AddProperty("test_number", 42);
customEvent.AddProperty("test_bool", true);
await AirshipDotNet.Airship.Analytics.TrackEvent(customEvent);
Console.WriteLine("TrackEvent test completed");
}
catch (Exception ex)
{
Console.WriteLine($"TrackEvent error: {ex}");
}
}
async void OnAssociateIdentifierClicked(object sender, EventArgs e)
{
try
{
await AirshipDotNet.Airship.Analytics.AssociateIdentifier("test_key", "test_value_" + DateTime.Now.Ticks);
Console.WriteLine("AssociateIdentifier test completed");
}
catch (Exception ex)
{
Console.WriteLine($"AssociateIdentifier error: {ex}");
}
}
// ==================== Contact Tests ====================
async void UpdateNamedUser()
{
namedUserLabel.Text = "";
try
{
var namedUser = await AirshipDotNet.Airship.Contact.GetNamedUser();
namedUserLabel.Placeholder = namedUser ?? "named user";
}
catch (Exception ex)
{
Console.WriteLine($"Error in UpdateNamedUser: {ex.Message}");
namedUserLabel.Placeholder = "Error loading named user";
}
}
async void OnIdentifyContactClicked(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(namedUserLabel.Text))
{
await AirshipDotNet.Airship.Contact.Reset();
}
else
{
await AirshipDotNet.Airship.Contact.Identify(namedUserLabel.Text);
}
UpdateNamedUser();
await DisplayAlert("Alert", "Named user added successfully", "OK");
}
catch (Exception ex)
{
Console.WriteLine($"Error adding named user: {ex.Message}");
await DisplayAlert("Error", "Failed to add named user", "OK");
}
}
// ==================== In-App Automation Tests ====================
async void OnSetPausedClicked(object sender, EventArgs e)
{
try
{
await AirshipDotNet.Airship.InApp.SetPaused(pauseAutomationSwitch.On);
Console.WriteLine($"SetPaused test completed: {pauseAutomationSwitch.On}");
}
catch (Exception ex)
{
Console.WriteLine($"SetPaused error: {ex}");
}
}
async void OnSetDisplayIntervalClicked(object sender, EventArgs e)
{
try
{
var interval = TimeSpan.FromSeconds(30);
await AirshipDotNet.Airship.InApp.SetDisplayInterval(interval);
Console.WriteLine("SetDisplayInterval test completed");
}
catch (Exception ex)
{
Console.WriteLine($"SetDisplayInterval error: {ex}");
}
}
}