Providers
Providers are designed to be small layers that run ON TOP of all the native cruft of implementing push. Underneath the hood, Android runs Firebase and iOS runs Apple push. There is no way around this. All 3rd party push mechanisms build on top of this model.
We have a couple of simple providers out of the box
Firebase
You may ask yourself, why firebase since it is built into Android. You would be correct. This provider is mainly to bring Firebase to iOS so you can use the firebase cloud messaging backend to send push notifications through.
IServiceCollection services; // get from your app builder
// if you use google-services.json or firebase plist on iOS, you can just use the followingservices.AddPushFirebaseMessaging<YourPushDelegate>();
// OR use manual registrationservices.AddPushFirebaseMessaging<YourPushDelegate>( false, "Firebase Provided AppId", "Firebase Provided SenderId", "Firebase Provided ProjectId", "Firebase Provided ApiKey");
Azure Notification Hubs
Our Azure Notification Hubs provider is a “base model”. We don’t support some of the cool features like templates or multiple connectionstrings. We don’t do this because we can’t assume how any user will manage these. If they change connection strings, where those connectionstrings come into play, etc. Please read below on creating your own custom provider
IServiceCollection services; // get from your app builder
services.AddPushAzureNotificationHubs<YourPushDelegate>( "Your Connection String", "Your Hub Name");
Creating Your Own Custom Provider
First - install into your project or wherever you are creating your push provider
Creating
This is an example push provider
using System.Threading.Tasks;
namespace MyNamespace;
public class MyCustomPushProvider : Shiny.Push.IPushProvider{ public MyCustomPushProvider() { // dependency injection works here, but treat this provider as a singleton }
#if ANDROID public Task<string> Register(string nativeToken) { // from here, you can make an http call to your server or any service you've injected }
public Task UnRegister() { // same as register, you can do whatever you need to asynchonously }#elif IOS || MACCATALYST public Task<string> Register(Foundation.NSData nativeToken) { // only difference between this and Android, is the raw native token sent from iOS }
public Task UnRegister() { ///... }#endif}
Registering
During your service host building (ie. MauiProgram.cs), do the following:
IServiceCollection services; // get from your app builder
services.AddPush(); // Add native push
// now, register your provider using: AddShinyServiceservices.AddShinyService<MyCustomPushProvider>();
Your MyCustomPushProvider will have access to all of the same dependency injection as every other service. You can call into it however you want, BUT - to start all of the push notification registration, still use the same Shiny.Push.IPushManager Register/UnRegister calls just as before.
Shiny will call into your provider as native push tokens change, a new registration is being requested, or unregister is being called.