From f78a542be216ad6c00fda491a69630a9e8a814fc Mon Sep 17 00:00:00 2001 From: Tihanyi Marcell Date: Mon, 12 Jun 2023 20:09:48 +0200 Subject: [PATCH] iOS notification permission fix --- filcnaplo/lib/main.dart | 46 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/filcnaplo/lib/main.dart b/filcnaplo/lib/main.dart index 9f62e1e..9f5c788 100644 --- a/filcnaplo/lib/main.dart +++ b/filcnaplo/lib/main.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:background_fetch/background_fetch.dart'; import 'package:filcnaplo/api/providers/user_provider.dart'; import 'package:filcnaplo/api/providers/database_provider.dart'; @@ -53,26 +55,32 @@ class Startup { FlutterLocalNotificationsPlugin(); // Get permission to show notifications - flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< + if (Platform.isAndroid) { + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin>()! - .requestPermission(); - await flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() - ?.requestPermissions( - alert: false, - badge: true, - sound: true, - ); - await flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() - ?.requestPermissions( - alert: false, - badge: true, - sound: true, - ); + .requestPermission(); + } + else if (Platform.isIOS) { + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() + ?.requestPermissions( + alert: false, + badge: true, + sound: true, + ); + } + else if (Platform.isMacOS) { + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + MacOSFlutterLocalNotificationsPlugin>() + ?.requestPermissions( + alert: false, + badge: true, + sound: true, + ); + } // Platform specific settings final DarwinInitializationSettings initializationSettingsDarwin =