Skip to content

Commit ab54314

Browse files
committed
Apple notifications tester
1 parent a56a363 commit ab54314

File tree

3 files changed

+65
-13
lines changed

3 files changed

+65
-13
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace CorePush.Tester
5+
{
6+
public class AppleNotification
7+
{
8+
public class ApsPayload
9+
{
10+
public class Alert
11+
{
12+
[JsonProperty("title")]
13+
public string Title { get; set; }
14+
15+
[JsonProperty("body")]
16+
public string Body { get; set; }
17+
}
18+
19+
[JsonProperty("alert")]
20+
public Alert AlertBody { get; set; }
21+
22+
[JsonProperty("apns-push-type")]
23+
public string PushType { get; set; } = "alert";
24+
}
25+
26+
public AppleNotification(Guid id, string message, string title = "")
27+
{
28+
Id = id;
29+
30+
Aps = new ApsPayload
31+
{
32+
AlertBody = new ApsPayload.Alert
33+
{
34+
Title = title,
35+
Body = message
36+
}
37+
};
38+
}
39+
40+
[JsonProperty("aps")]
41+
public ApsPayload Aps { get; set; }
42+
43+
[JsonProperty("id")]
44+
public Guid Id { get; set; }
45+
}
46+
}

CorePush.Tester/CorePush.Tester.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
5+
<TargetFrameworks>net5.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>
99
<ProjectReference Include="..\CorePush\CorePush.csproj" />
1010
</ItemGroup>
1111

12+
<ItemGroup>
13+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
14+
</ItemGroup>
15+
1216
</Project>

CorePush.Tester/Program.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class Program
1010
{
1111
#region Apn Sender Settings
1212

13-
private const string apnBundleId = "";
14-
private const string apnP8PrivateKey = "";
15-
private const string apnP8PrivateKeyId = "";
16-
private const string apnTeamId = "";
17-
private const string apnDeviceToken = "";
13+
private const string apnBundleId = "TODO";
14+
private const string apnP8PrivateKey = "TODO";
15+
private const string apnP8PrivateKeyId = "TODO";
16+
private const string apnTeamId = "TODO";
17+
private const string apnDeviceToken = "TODO";
1818
private const ApnServerType apnServerType = ApnServerType.Development;
1919

2020
#endregion
@@ -26,7 +26,7 @@ class Program
2626

2727
# endregion
2828

29-
private static HttpClient http = new HttpClient();
29+
private static readonly HttpClient http = new HttpClient();
3030

3131
static async Task Main()
3232
{
@@ -47,13 +47,15 @@ private static async Task SendApnNotificationAsync()
4747
ServerType = apnServerType,
4848
};
4949

50-
var apn = new ApnSender(settings, http);
51-
var payload = new
50+
while (true)
5251
{
53-
notification = new { body = "Hello World!" }
54-
};
55-
56-
await apn.SendAsync(payload, apnDeviceToken);
52+
var apn = new ApnSender(settings, http);
53+
var payload = new AppleNotification(
54+
Guid.NewGuid(),
55+
"Hello World (Message)",
56+
"Hello World (Title)");
57+
var response = await apn.SendAsync(payload, apnDeviceToken);
58+
}
5759
}
5860

5961
private static async Task SendFcmNotificationAsync()

0 commit comments

Comments
 (0)