Last active
March 26, 2021 10:35
-
-
Save xleon/e4522e6ffb84eb9d2810675a1994aeae to your computer and use it in GitHub Desktop.
Firebase Cloud Management in XAMARIN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<PackageReference Include="Xamarin.Firebase.Messaging" Version="121.0.1" /> | |
<PackageReference Include="Xamarin.GooglePlayServices.Base" Version="117.6.0" /> | |
<PackageReference Include="Xamarin.Google.Dagger" Version="2.27.0" /> <!-- Fixes runtime error class not found --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[...] | |
<application android:label="MyApp" android:icon="@mipmap/ic_launcher" android:theme="@style/Theme.App.New" android:largeHeap="true" android:hardwareAccelerated="true" android:networkSecurityConfig="@xml/network_security_config" android:allowBackup="false"> | |
<receiver | |
android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" | |
android:exported="false" /> | |
<receiver | |
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" | |
android:exported="true" | |
android:permission="com.google.android.c2dm.permission.SEND"> | |
<intent-filter> | |
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> | |
<action android:name="com.google.android.c2dm.intent.REGISTRATION" /> | |
<category android:name="${applicationId}" /> | |
</intent-filter> | |
</receiver> | |
</application> | |
[...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.App; | |
using DryIoc; | |
using Firebase.Messaging; | |
using App.Core.InversionOfControl; | |
using App.Extensions; | |
using App.Providers.Settings; | |
namespace App.Droid.Service.Push | |
{ | |
[Service] | |
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })] | |
public class MyFirebaseMessagingService : FirebaseMessagingService, IEnableAppLogger | |
{ | |
public override void OnNewToken(string token) | |
{ | |
this.Log()?.Warning($"Saving Firebase token to settings.. ({token})"); | |
Ioc | |
.Container | |
.Resolve<ISettingsProvider>() | |
.PushNotificationToken = token; | |
this.Log()?.Warning($"Firebase token saved to settings!"); | |
} | |
public override void OnMessageReceived(RemoteMessage remoteMessage) | |
{ | |
var notification = remoteMessage.GetNotification(); | |
this.Log().Debug(notification.Body); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment