Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa3907 committed May 24, 2024
1 parent c9762ee commit e1ba4bc
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 90 deletions.
6 changes: 0 additions & 6 deletions src/DotNet.Push.Maui/DotNet.Push.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@

</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
<CodesignKey>Apple Development: SEONGAHN LEE (1234567890)</CodesignKey>
<CodesignProvision>Dotnet Push for Development</CodesignProvision>
<ProvisioningType>manual</ProvisioningType>
</PropertyGroup>

<ItemGroup>
<BundleResource Include="Platforms/iOS/Entitlements.plist">
<CodesignEntitlements>Platforms/iOS/Entitlements.plist</CodesignEntitlements>
Expand Down
4 changes: 2 additions & 2 deletions src/DotNet.Push.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static async Task Main(string[] args)
else if (_test_phone == "IA2")
{
var json = File.ReadAllText(@"path/to/serviceAccountKey.json");
var _fcm = new PushNotifyFCMV1("<project-id>", "<server-id>", "<alarm-tag>", json);
var _fcm = new PushNotifyFCMV1(json);

var _result = await _fcm.SendNotificationAsync("<device-token>", "<priority>", "<title>", "<click-action>", "<message>", 1, "<icon-name>", "<color>");

Expand All @@ -48,7 +48,7 @@ private static async Task Main(string[] args)
else if (_test_phone == "AF2")
{
var json = File.ReadAllText(@"path/to/serviceAccountKey.json");
var _fcm = new PushNotifyFCMV1("<project-id>", "<server-id>", "<alarm-tag>", json);
var _fcm = new PushNotifyFCMV1(json);

var _result = await _fcm.SendNotificationAsync("<device-token>", "<priority>", "<title>", "<click-action>", "<message>", 1, "<icon-name>", "<color>");

Expand Down
148 changes: 66 additions & 82 deletions src/DotNet.Push/PushNotifyFCMV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,108 +5,92 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace DotNet.Push
namespace DotNet.Push;

public class PushNotifyFCMV1
{
public class PushNotifyFCMV1
public PushNotifyFCMV1(string json)
{
public PushNotifyFCMV1(string json)
FirebaseApp.Create(new AppOptions()
{
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromJson(json),
});
}
Credential = GoogleCredential.FromJson(json),
});
}

public PushNotifyFCMV1(string projectId, string serverId, string alarmTag, string json) : this(json)
{
ProjectId = projectId;
ServerId = serverId;
AlarmTag = alarmTag;
}
/// <summary>
///
/// </summary>
/// <param name="deviceToken"></param>
/// <param name="priority">high,normal</param>
/// <param name="title"></param>
/// <param name="clickAction"></param>
/// <param name="message"></param>
/// <param name="badge"></param>
/// <param name="iconName"></param>
/// <param name="color"></param>
/// <returns></returns>
public async Task<(bool success, string message)> SendNotificationAsync(string deviceToken, string priority, string title, string clickAction, string message, int badge, string iconName, string color)
{
var result = (success: false, message: "ok");

/// <summary>
///
/// </summary>
/// <param name="deviceToken"></param>
/// <param name="priority">high,normal</param>
/// <param name="title"></param>
/// <param name="clickAction"></param>
/// <param name="message"></param>
/// <param name="badge"></param>
/// <param name="iconName"></param>
/// <param name="color"></param>
/// <returns></returns>
public async Task<(bool success, string message)> SendNotificationAsync(string deviceToken, string priority, string title, string clickAction, string message, int badge, string iconName, string color)
try
{
var result = (success: false, message: "ok");

try
var request = new Message()
{
var request = new Message()
Token = deviceToken,
Notification = new Notification()
{
Title = title,
Body = message
},
Apns = new ApnsConfig()
{
Token = deviceToken,
Notification = new Notification()
Headers = new Dictionary<string, string>()
{
Title = title,
Body = message,
{ "apns-priority", priority == "high" ? "10" : "5" }
},
Android = new AndroidConfig()
Aps = new Aps()
{
Priority = priority == "high" ? Priority.High : Priority.Normal,
Notification = new AndroidNotification()
Alert = new ApsAlert()
{
ClickAction = clickAction,
Icon = iconName,
Color = color,
Title = title,
Body = message
},
},
Data = new Dictionary<string, string>()
Badge = badge,
Sound = "default",
ContentAvailable = true,
MutableContent = true
}
},
Android = new AndroidConfig()
{
Priority = priority == "high" ? Priority.High : Priority.Normal,
Notification = new AndroidNotification()
{
{ "title", title },
{ "badge", badge.ToString() },
{ "message", message },
ClickAction = clickAction,
Icon = iconName,
Color = color,
}
};

var messaging = FirebaseMessaging.DefaultInstance;
var response = await messaging.SendAsync(request);

result.message = response;
result.success = true;
}
catch (Exception ex)
{
result.message = $"exception: '{ex.Message}'";
}
},
Data = new Dictionary<string, string>()
{
{ "title", title },
{ "badge", badge.ToString() },
{ "message", message }
}
};

return result;
}
var messaging = FirebaseMessaging.DefaultInstance;
var response = await messaging.SendAsync(request);

/// <summary>
///
/// </summary>
public string ProjectId
{
get;
set;
result.message = response;
result.success = true;
}

/// <summary>
///
/// </summary>
public string ServerId
catch (Exception ex)
{
get;
set;
result.message = $"exception: '{ex.Message}'";
}

/// <summary>
///
/// </summary>
public string AlarmTag
{
get;
set;
}
return result;
}
}

0 comments on commit e1ba4bc

Please sign in to comment.