4 Commits
Author SHA1 Message Date
ivanszabo 1f4fce1e42 X 2025-05-15 14:45:00 +02:00
ivanszabo 73a4b9a445 Na most kaptam TOKENT!!! 2025-05-15 09:39:33 +02:00
ivanszabo 9df2854a3c Firebase teszthez 2025-05-15 09:28:08 +02:00
ivanszabo 7efd090b86 Forebird.CloudMessages implementálása 2025-05-14 21:56:33 +02:00
9 changed files with 134 additions and 5 deletions
+20 -2
View File
@@ -12,7 +12,12 @@ using Microsoft.Maui.Hosting;
using CommunityToolkit.Maui.Core;
using WorkFlowCheck.MAUI.Handlers;
using WorkFlowCheck.MAUI.Helper;
using Plugin.Firebase.CloudMessaging;
using Microsoft.Maui.LifecycleEvents;
#if ANDROID
using Plugin.Firebase.Core.Platforms.Android;
#endif
namespace WorkFlowCheck.MAUI
{
public static class MauiProgram
@@ -46,7 +51,7 @@ namespace WorkFlowCheck.MAUI
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("FontAwesome.ttf", "FontAwesome");
})
.RegisterFirebaseServices()
.UseMauiCommunityToolkitCore()
.UseMauiCommunityToolkit();
#if DEBUG
@@ -63,11 +68,24 @@ namespace WorkFlowCheck.MAUI
}).GetAwaiter().GetResult();
}
ServiceProvider = app.Services;
return app;
}
public static IServiceProvider ServiceProvider { get; private set; }
private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
{
builder.ConfigureLifecycleEvents(events =>
{
#if ANDROID
events.AddAndroid(android => android.OnCreate((activity, _) =>
CrossFirebase.Initialize(activity)));
#endif
});
return builder;
}
}
}
@@ -1,5 +1,6 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;
using Plugin.Firebase.CloudMessaging;
using System.Drawing;
using WorkFlowCheck.MAUI.Helper;
using WorkFlowCheck.MAUI.Pages.NFC;
@@ -14,6 +15,7 @@ public partial class LoginPage : BasePage
public LoginPage()
{
InitializeComponent();
InitFirebase();
SetContent(LoginContent);
_userService = MauiProgram.ServiceProvider.GetRequiredService<IUserService>();
_syncService = MauiProgram.ServiceProvider.GetRequiredService<ISyncService>();
@@ -166,4 +168,23 @@ public partial class LoginPage : BasePage
}
}
private async void InitFirebase()
{
try
{
await CrossFirebaseCloudMessaging.Current.CheckIfValidAsync();
var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync();
await _syncService.UploadFCMToken(token);
}
catch (Exception ex)
{
await SystemHelper.ShowSnackBar("FCM üzenetküldõ inicializálása SIKERTELEN!",
SystemHelper.ColorToHex(Colors.Red),
SystemHelper.ColorToHex(Colors.Red),
SystemHelper.ColorToHex(Colors.Yellow),
15);
}
}
}
@@ -15,6 +15,21 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="default" />
<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>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
@@ -23,5 +38,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
</manifest>
@@ -3,6 +3,8 @@ using Android.Content;
using Android.Content.PM;
using Android.Nfc;
using Android.OS;
using Firebase;
using Plugin.Firebase.CloudMessaging;
using Plugin.NFC;
@@ -34,18 +36,21 @@ namespace WorkFlowCheck.MAUI
protected override void OnCreate(Bundle savedInstanceState)
{
CrossNFC.Init(this);
Firebase.FirebaseApp.InitializeApp(this);
base.OnCreate(savedInstanceState);
nfcAdapter = NfcAdapter.GetDefaultAdapter(this);
pendingIntent = PendingIntent.GetActivity(this, 0,
new Intent(this, typeof(MainActivity)).AddFlags(ActivityFlags.SingleTop),
Build.VERSION.SdkInt >= BuildVersionCodes.S ? PendingIntentFlags.Mutable : PendingIntentFlags.UpdateCurrent);
HandleIntent(Intent);
CreateNotificationChannelIfNeeded();
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
HandleIntent(intent);
CrossNFC.OnNewIntent(intent);
if (intent.Action == NfcAdapter.ActionTagDiscovered)
@@ -85,5 +90,24 @@ namespace WorkFlowCheck.MAUI
// nfcAdapter?.DisableForegroundDispatch(this);
//}
}
private static void HandleIntent(Intent intent)
{
FirebaseCloudMessagingImplementation.OnNewIntent(intent);
}
private void CreateNotificationChannelIfNeeded()
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
CreateNotificationChannel();
}
}
private void CreateNotificationChannel()
{
var channelId = $"{PackageName}.general";
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
notificationManager.CreateNotificationChannel(channel);
FirebaseCloudMessagingImplementation.ChannelId = channelId;
}
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<string name="com.google.firebase.crashlytics.mapping_file_id">none</string>
</resources>
@@ -26,5 +26,7 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress);
Task SyncUsers_Down(Action<double, string> reportProgress);
Task<bool> UploadFCMToken(string token);
}
}
@@ -512,5 +512,40 @@ namespace WorkFlowCheck.MAUI.Services
}
}
public async Task<ApiResponseDTO<bool>> UploadFCMToken(string token)
{
var retVal = new ApiResponseDTO<bool>();
try
{
string endpoint = $"{_httpClient.BaseAddress}api/fcm/SendFCMToken";
var FCMMessageDTO = new FCMMessageDTO()
{
Token = token,
UserId = _userService.GetCurrentUser()?.Id
};
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, FCMMessageDTO))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseDTO<bool>>(jsonString);
return response ?? new ApiResponseDTO<bool>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<bool>
{
IsSuccess = false
};
}
}
}
}
@@ -36,7 +36,9 @@
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>-->
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
<GoogleServicesJson Include="Platforms\Android\google-services.json" />
</ItemGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
@@ -54,6 +56,9 @@
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<AndroidResource Remove="Platforms\Android\Resources\values\strings.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Platforms\Android\Resources\xml\file_paths.xml" />
@@ -83,6 +88,8 @@
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Plugin.Firebase.Auth" Version="3.1.1" />
<PackageReference Include="Plugin.Firebase.CloudMessaging" Version="3.1.2" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />