All Projects → andrei-m-code → Net Core Push Notifications

andrei-m-code / Net Core Push Notifications

Licence: mit
Lightweight .NET Core Push Notifications for Android and iOS

Projects that are alternatives of or similar to Net Core Push Notifications

Pushy
A Java library for sending APNs (iOS/macOS/Safari) push notifications
Stars: ✭ 1,353 (+1188.57%)
Mutual labels:  notifications, push-notifications, apns
Uniqush Push
Uniqush is a free and open source software system which provides a unified push service for server side notification to apps on mobile devices.
Stars: ✭ 1,238 (+1079.05%)
Mutual labels:  push-notifications, apns, fcm
Apnotic
A Ruby APNs HTTP/2 gem able to provide instant feedback.
Stars: ✭ 360 (+242.86%)
Mutual labels:  apple, notifications, apns
node-apn-http2
Communicate with Apple Push Notification Service via native Node.js v8.8.1+ HTTP2 module (node-apn drop-in)
Stars: ✭ 25 (-76.19%)
Mutual labels:  apple, push-notifications, apns
Airnotifier
Push Notifications Server for Human Beings.
Stars: ✭ 522 (+397.14%)
Mutual labels:  notifications, apns, fcm
MongoosePush
MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS.
Stars: ✭ 101 (-3.81%)
Mutual labels:  notifications, apns, fcm
Notificationpusher
Standalone PHP library for easy devices notifications push.
Stars: ✭ 1,143 (+988.57%)
Mutual labels:  notifications, push-notifications, apns
apns2
Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens
Stars: ✭ 66 (-37.14%)
Mutual labels:  apple, push-notifications, apns
Node Pushnotifications
Push notifications for GCM, APNS, MPNS, AMZ (automatic detection from device token)
Stars: ✭ 432 (+311.43%)
Mutual labels:  push-notifications, apns, fcm
Aerogear Unifiedpush Server
🚀 AeroGear UnifiedPush Server
Stars: ✭ 432 (+311.43%)
Mutual labels:  push-notifications, apns, fcm
azure-notificationhubs-java-backend
Azure Notification Hubs SDK for Java
Stars: ✭ 31 (-70.48%)
Mutual labels:  push-notifications, apns, fcm
Onesignal Ionic Example
Stars: ✭ 89 (-15.24%)
Mutual labels:  push-notifications, apns, fcm
mod push appserver
Simple and extendable appserver for XMPP pushes (aka. XEP-0357)
Stars: ✭ 24 (-77.14%)
Mutual labels:  push-notifications, apns, fcm
Apns4erl
Apple Push Notification Server for Erlang
Stars: ✭ 352 (+235.24%)
Mutual labels:  apple, notifications, apns
PUSHTestFCM
[FireMonkey] Push test project
Stars: ✭ 17 (-83.81%)
Mutual labels:  notifications, apns, fcm
Onesignal Ios Sdk
OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your native iOS app with OneSignal. https://onesignal.com
Stars: ✭ 370 (+252.38%)
Mutual labels:  notifications, push-notifications, apns
andpush
Android Push Notification in Ruby: The fastest client for FCM (Firebase Cloud Messaging)
Stars: ✭ 83 (-20.95%)
Mutual labels:  notifications, push-notifications, fcm
Gunfish
No description or website provided.
Stars: ✭ 35 (-66.67%)
Mutual labels:  apple, push-notifications, apns
Pushnotification
PHP and Laravel Package to send push notifications to Android and IOS devices.
Stars: ✭ 395 (+276.19%)
Mutual labels:  push-notifications, apns, fcm
Socket.io Push
整合了小米,华为,友盟,谷歌,苹果推送的统一解决方案
Stars: ✭ 605 (+476.19%)
Mutual labels:  notifications, push-notifications, apns

Build Status NuGet

.NET Core Push Notifications for Android and iOS

CorePush is a simple .NET Core library for sending Push Notifications for Android Firebase (FCM) and iOS (APN) with JWT HTTP/2 API. It's very lightweight and only has basic functionality. Please contribute or open github issue if you need additional features. Thank you for using it!

Installation

NuGet Package

The easiest way would be to use nuget package.

dotnet cli:

dotnet add package CorePush

Package Manager Console:

Install-Package CorePush

Setup for ASP.NET Core and/or other Dependency Injection

Both ApnSender and FcmSender have dependencies that need to be registered in order to enable DI.

  1. Register HttpClient in Startup.cs:
services.AddHttpClient();
  1. Register settings as a singleton:

If you've added ApnSettings and FcmSettings into a configuration section, you can bind section directly to settings object from IConfiguration available in Startup.cs:

var section = configuration.GetSection("ApnSettings");
var settings = new AppSettings();
section.Bind(settings);

Add settings to services:

services.AddSingleton(apnSettings);
services.AddSingleton(fcmSettings);

Firebase Cloud Messages for Android and iOS

For Firebase messages (aka FCM) we will need project Server Key and Sender ID. To find Server Key and Sender ID go to Firebase Console (https://console.firebase.google.com), select your project, then go to project settings -> cloud messaging. You should be able to find everything you need there. Here is a simple example of how you send Firebase notification:

var fcm = new FcmSender(settings, httpClient);
await fcm.SendAsync(deviceToken, notification);

If you want to use Firebase to send iOS notifications, please checkout this article: https://firebase.google.com/docs/cloud-messaging/ios/certs. The library serializes notification object to JSON using Newtonsoft.Json library and sends it to Google cloud. Here is more details on the expected payloads for FCM https://firebase.google.com/docs/cloud-messaging/concept-options#notifications. Please note, we are setting the "to" property to use device token, so you don't have to do it yourself.

Apple Push Notifications

To send notifications to Apple devices you have to create a publisher profile and pass settings object with necessary parameters to ApnSender constructor. Apn Sender will create and sign JWT token and attach it to every request to Apple servers:

  1. P8 private key - p8 certificate generated in itunes. Just 1 line string without spaces, ----- or line breaks.
  2. Private key id - 10 digit p8 certificate id. Usually a part of a downloadable certificate filename e.g. AuthKey_IDOFYOURCR.p8
  3. Team id - Apple 10 digit team id from itunes
  4. App bundle identifier - App slug / bundle name e.g.com.mycompany.myapp
  5. Server type - Development or Production APN server
var apn = new ApnSender(settings, httpClient);
await apn.SendAsync(notification, deviceToken);

IMPORTANT: Initialize 1 ApnSender per bundle. When you send many messages at once make sure to retry the sending in case of an error. If error happens it's recommended to retry the call after 1 second delay (await Task.Delay(1000)). Apple typically doesn't like to receive too many messages and will ocasionally respond with HTTP 429. From my experiance it happens once per 1000 requests.

Please see Apple notification format examples here: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1. Tip: To send properties like {"content-available": true} you can use Newtonsoft.Json attributes over C# properties like [JsonProperty("content-available")].

Examples of notification payload

You can find expected notification formats for different types of notifications in the documentation. To make it easier to get started, here is a simple example of visible notification (the one that you'll see in phone's notification center) for iOS and Android:

public class GoogleNotification
{
    public class DataPayload
    {
        // Add your custom properties as needed
        [JsonProperty("message")]
        public string Message { get; set; }
    }

    [JsonProperty("priority")]
    public string Priority { get; set; } = "high";

    [JsonProperty("data")]
    public DataPayload Data { get; set; }
}

public class AppleNotification
{
    public class ApsPayload
    {
        [JsonProperty("alert")]
        public string AlertBody { get; set; }
    }

    // Your custom properties as needed

    [JsonProperty("aps")]
    public ApsPayload Aps { get; set; }
}

Use [JsonProperty("alert-type")] attribute to serialize C# properties into JSON properties with dashes.

Known Issues

  • Doesn't seem like it's running on Mono #55 (Help Wanted!).

MIT License

Copyright (c) 2020 Andrei M

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].