-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathProgram.cs
86 lines (70 loc) · 2.3 KB
/
Program.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using CorePush.Apple;
using CorePush.Firebase;
using CorePush.Serialization;
namespace CorePush.Tester;
class Program
{
#region Apn Sender Settings
private const string apnBundleId = "TODO";
private const string apnP8PrivateKey = "TODO";
private const string apnP8PrivateKeyId = "TODO";
private const string apnTeamId = "TODO";
private const string apnDeviceToken = "TODO";
private const ApnServerType apnServerType = ApnServerType.Production;
#endregion
#region FCM Sender Settings
private const string fcmServiceAccountFilename = "TODO";
private const string fcmReceiverToken = "TODO";
# endregion
private static readonly HttpClient http = new();
static async Task Main()
{
// await SendApnNotificationAsync();
await SendFirebaseNotificationAsync();
Console.WriteLine("Done!");
}
private static async Task SendApnNotificationAsync()
{
var settings = new ApnSettings
{
AppBundleIdentifier = apnBundleId,
P8PrivateKey = apnP8PrivateKey,
P8PrivateKeyId = apnP8PrivateKeyId,
TeamId = apnTeamId,
ServerType = apnServerType,
};
while (true)
{
var apn = new ApnSender(settings, http);
var payload = new AppleNotification(
Guid.NewGuid(),
"Hello World (Message)",
"Hello World (Title)");
var response = await apn.SendAsync(payload, apnDeviceToken);
}
}
private static async Task SendFirebaseNotificationAsync()
{
var contents = await File.ReadAllTextAsync(fcmServiceAccountFilename);
var serializer = new DefaultCorePushJsonSerializer();
var settings = serializer.Deserialize<FirebaseSettings>(contents);
var fcm = new FirebaseSender(settings, http);
var payload = new
{
message = new
{
token = fcmReceiverToken,
notification = new
{
title = "Test",
body = "Test Body"
}
}
};
var response = await fcm.SendAsync(payload);
}
}