Implementate notifiche
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="it.integry.salesbook">
|
||||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:usesCleartextTraffic="true" android:supportsRtl="true">
|
||||
<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">
|
||||
@@ -15,4 +15,10 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.BATTERY_STATS" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
</manifest>
|
||||
13
salesbook.Maui/Platforms/Android/AndroidModule.cs
Normal file
13
salesbook.Maui/Platforms/Android/AndroidModule.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using salesbook.Maui.Core;
|
||||
using salesbook.Shared.Core.Interface.System.Battery;
|
||||
|
||||
namespace salesbook.Maui;
|
||||
|
||||
public static class AndroidModule
|
||||
{
|
||||
public static MauiAppBuilder RegisterAndroidAppServices(this MauiAppBuilder mauiAppBuilder)
|
||||
{
|
||||
mauiAppBuilder.Services.AddSingleton<IBatteryOptimizationManagerService, BatteryOptimizationManagerService>();
|
||||
return mauiAppBuilder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Provider;
|
||||
using salesbook.Shared.Core.Interface.System.Battery;
|
||||
using Application = Android.App.Application;
|
||||
|
||||
namespace salesbook.Maui.Core;
|
||||
|
||||
public class BatteryOptimizationManagerService : IBatteryOptimizationManagerService
|
||||
{
|
||||
public bool IsBatteryOptimizationEnabled()
|
||||
{
|
||||
var packageName = AppInfo.PackageName;
|
||||
|
||||
var pm = (PowerManager)Application.Context.GetSystemService(Context.PowerService)!;
|
||||
return !pm.IsIgnoringBatteryOptimizations(packageName);
|
||||
}
|
||||
|
||||
public void OpenBatteryOptimizationSettings(Action<bool> onCompleted)
|
||||
{
|
||||
var packageName = AppInfo.PackageName;
|
||||
|
||||
var intent = new Intent(Settings.ActionRequestIgnoreBatteryOptimizations);
|
||||
intent.SetData(Android.Net.Uri.Parse("package:" + packageName));
|
||||
((MainActivity)Platform.CurrentActivity!).StartActivityForResult(intent, (result, _) => { onCompleted(result == Result.Ok); });
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,42 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Content.PM;
|
||||
|
||||
namespace salesbook.Maui
|
||||
{
|
||||
[Activity(Theme = "@style/Maui.SplashTheme",
|
||||
[Activity(
|
||||
Theme = "@style/Maui.SplashTheme",
|
||||
MainLauncher = true,
|
||||
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode |
|
||||
ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
|
||||
[IntentFilter([Shiny.ShinyPushIntents.NotificationClickAction],
|
||||
Categories = new[]
|
||||
{
|
||||
|
||||
[IntentFilter(
|
||||
[
|
||||
Shiny.ShinyPushIntents.NotificationClickAction
|
||||
],
|
||||
Categories =
|
||||
[
|
||||
"android.intent.category.DEFAULT"
|
||||
}
|
||||
]
|
||||
)]
|
||||
public class MainActivity : MauiAppCompatActivity
|
||||
{
|
||||
private readonly IDictionary<int, Action<Result, Intent>> _onActivityResultSubscriber =
|
||||
new Dictionary<int, Action<Result, Intent>>();
|
||||
|
||||
public void StartActivityForResult(Intent intent, Action<Result, Intent> onResultAction)
|
||||
{
|
||||
var requestCode = new Random(DateTime.Now.Millisecond).Next();
|
||||
_onActivityResultSubscriber.Add(requestCode, onResultAction);
|
||||
StartActivityForResult(intent, requestCode);
|
||||
}
|
||||
|
||||
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
|
||||
{
|
||||
if (_onActivityResultSubscriber.TryGetValue(requestCode, out var value))
|
||||
value(resultCode, data);
|
||||
|
||||
base.OnActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
using Android.App;
|
||||
using Android.Runtime;
|
||||
|
||||
namespace salesbook.Maui
|
||||
{
|
||||
[Application(HardwareAccelerated = true)]
|
||||
public class MainApplication : MauiApplication
|
||||
{
|
||||
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
|
||||
: base(handle, ownership)
|
||||
{
|
||||
}
|
||||
namespace salesbook.Maui;
|
||||
|
||||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
|
||||
[Application(HardwareAccelerated = true)]
|
||||
public class MainApplication : MauiApplication
|
||||
{
|
||||
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
|
||||
: base(handle, ownership)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiAppBuilder()
|
||||
.RegisterAndroidAppServices().Build();
|
||||
}
|
||||
@@ -1,10 +1,24 @@
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace salesbook.Maui
|
||||
{
|
||||
[Register("AppDelegate")]
|
||||
public class AppDelegate : MauiUIApplicationDelegate
|
||||
{
|
||||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
|
||||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiAppBuilder()
|
||||
.RegisterIosAppServices().Build();
|
||||
|
||||
[Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")]
|
||||
public void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
|
||||
=> global::Shiny.Hosting.Host.Lifecycle.OnRegisteredForRemoteNotifications(deviceToken);
|
||||
|
||||
[Export("application:didFailToRegisterForRemoteNotificationsWithError:")]
|
||||
public void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
|
||||
=> global::Shiny.Hosting.Host.Lifecycle.OnFailedToRegisterForRemoteNotifications(error);
|
||||
|
||||
[Export("application:didReceiveRemoteNotification:fetchCompletionHandler:")]
|
||||
public void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
|
||||
=> global::Shiny.Hosting.Host.Lifecycle.OnDidReceiveRemoteNotification(userInfo, completionHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using salesbook.Shared.Core.Interface.System.Battery;
|
||||
|
||||
namespace salesbook.Maui.Core;
|
||||
|
||||
public class BatteryOptimizationManagerService : IBatteryOptimizationManagerService
|
||||
{
|
||||
public bool IsBatteryOptimizationEnabled() => true;
|
||||
|
||||
public void OpenBatteryOptimizationSettings(Action<bool> onCompleted)
|
||||
{
|
||||
}
|
||||
}
|
||||
110
salesbook.Maui/Platforms/iOS/PrivacyInfo.xcprivacy
Normal file
110
salesbook.Maui/Platforms/iOS/PrivacyInfo.xcprivacy
Normal file
@@ -0,0 +1,110 @@
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPIType</key>
|
||||
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
|
||||
<key>NSPrivacyAccessedAPITypeReasons</key>
|
||||
<array>
|
||||
<string>C617.1</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPIType</key>
|
||||
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
|
||||
<key>NSPrivacyAccessedAPITypeReasons</key>
|
||||
<array>
|
||||
<string>35F9.1</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPIType</key>
|
||||
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
|
||||
<key>NSPrivacyAccessedAPITypeReasons</key>
|
||||
<array>
|
||||
<string>E174.1</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPIType</key>
|
||||
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
|
||||
<key>NSPrivacyAccessedAPITypeReasons</key>
|
||||
<array>
|
||||
<string>CA92.1</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array>
|
||||
<!--user info-->
|
||||
<dict>
|
||||
<key>NSPrivacyCollectedDataTypeUserID</key>
|
||||
<string>NSPrivacyCollectedDataTypeLocation</string>
|
||||
<key>NSPrivacyCollectedDataTypeLinked</key>
|
||||
<true />
|
||||
<key>NSPrivacyCollectedDataTypeTracking</key>
|
||||
<false />
|
||||
<key>NSPrivacyCollectedDataTypePurposes</key>
|
||||
<array>
|
||||
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>NSPrivacyCollectedDataTypeEmailAddress</key>
|
||||
<string>NSPrivacyCollectedDataTypeLocation</string>
|
||||
<key>NSPrivacyCollectedDataTypeLinked</key>
|
||||
<true />
|
||||
<key>NSPrivacyCollectedDataTypeTracking</key>
|
||||
<false />
|
||||
<key>NSPrivacyCollectedDataTypePurposes</key>
|
||||
<array>
|
||||
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>NSPrivacyCollectedDataTypePhoneNumber</key>
|
||||
<string>NSPrivacyCollectedDataTypeLocation</string>
|
||||
<key>NSPrivacyCollectedDataTypeLinked</key>
|
||||
<true />
|
||||
<key>NSPrivacyCollectedDataTypeTracking</key>
|
||||
<false />
|
||||
<key>NSPrivacyCollectedDataTypePurposes</key>
|
||||
<array>
|
||||
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
|
||||
</array>
|
||||
</dict>
|
||||
|
||||
<!--crashlytics/analytics-->
|
||||
<dict>
|
||||
<key>NSPrivacyCollectedDataType</key>
|
||||
<string>NSPrivacyCollectedDataTypeOtherDiagnosticData</string>
|
||||
<key>NSPrivacyCollectedDataTypeLinked</key>
|
||||
<false />
|
||||
<key>NSPrivacyCollectedDataTypeTracking</key>
|
||||
<false />
|
||||
<key>NSPrivacyCollectedDataTypePurposes</key>
|
||||
<array>
|
||||
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>NSPrivacyCollectedDataType</key>
|
||||
<string>NSPrivacyCollectedDataTypeCrashData</string>
|
||||
<key>NSPrivacyCollectedDataTypeLinked</key>
|
||||
<true />
|
||||
<key>NSPrivacyCollectedDataTypeTracking</key>
|
||||
<false />
|
||||
<key>NSPrivacyCollectedDataTypePurposes</key>
|
||||
<array>
|
||||
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
|
||||
</array>
|
||||
</dict>
|
||||
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
13
salesbook.Maui/Platforms/iOS/iOSModule.cs
Normal file
13
salesbook.Maui/Platforms/iOS/iOSModule.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using salesbook.Maui.Core;
|
||||
using salesbook.Shared.Core.Interface.System.Battery;
|
||||
|
||||
namespace salesbook.Maui;
|
||||
|
||||
public static class iOSModule
|
||||
{
|
||||
public static MauiAppBuilder RegisterIosAppServices(this MauiAppBuilder mauiAppBuilder)
|
||||
{
|
||||
mauiAppBuilder.Services.AddSingleton<IBatteryOptimizationManagerService, BatteryOptimizationManagerService>();
|
||||
return mauiAppBuilder;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user