Skip to content

Commit

Permalink
Fix: permissions related issues for both Platforms (#499)
Browse files Browse the repository at this point in the history
* fix: setup notification permission ios

* fix: add platform check for permissions related to Android only
  • Loading branch information
0xharkirat committed Mar 10, 2024
1 parent f35c586 commit bae50ea
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 40 deletions.
12 changes: 12 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,17 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)

target.build_configurations.each do |config|
# You can remove unused permissions here
# for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
# e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',

## dart: PermissionGroup.notification
'PERMISSION_NOTIFICATIONS=1',
]
end
end
end
49 changes: 27 additions & 22 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -693,21 +693,21 @@ PODS:
- firebase_core (2.24.2):
- Firebase/CoreOnly (= 10.18.0)
- Flutter
- FirebaseAppCheckInterop (10.21.0)
- FirebaseAppCheckInterop (10.22.0)
- FirebaseCore (10.18.0):
- FirebaseCoreInternal (~> 10.0)
- GoogleUtilities/Environment (~> 7.12)
- GoogleUtilities/Logger (~> 7.12)
- FirebaseCoreExtension (10.21.0):
- FirebaseCoreExtension (10.22.0):
- FirebaseCore (~> 10.0)
- FirebaseCoreInternal (10.21.0):
- FirebaseCoreInternal (10.22.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseFirestore (10.18.0):
- FirebaseCore (~> 10.0)
- FirebaseCoreExtension (~> 10.0)
- FirebaseFirestoreInternal (~> 10.17)
- FirebaseSharedSwift (~> 10.0)
- FirebaseFirestoreInternal (10.21.0):
- FirebaseFirestoreInternal (10.22.0):
- abseil/algorithm (~> 1.20220623.0)
- abseil/base (~> 1.20220623.0)
- abseil/container/flat_hash_map (~> 1.20220623.0)
Expand All @@ -720,8 +720,8 @@ PODS:
- FirebaseCore (~> 10.0)
- "gRPC-C++ (~> 1.49.1)"
- leveldb-library (~> 1.22)
- nanopb (< 2.30910.0, >= 2.30908.0)
- FirebaseSharedSwift (10.21.0)
- nanopb (< 2.30911.0, >= 2.30908.0)
- FirebaseSharedSwift (10.22.0)
- fl_location (0.0.1):
- Flutter
- Flutter (1.0.0)
Expand All @@ -740,7 +740,7 @@ PODS:
- Flutter
- FlutterMacOS
- GoogleSignIn (~> 7.0)
- GoogleDataTransport (9.3.0):
- GoogleDataTransport (9.4.0):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
Expand All @@ -765,13 +765,18 @@ PODS:
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSString+URLArguments (= 2.3.2)"
- "GoogleToolboxForMac/NSString+URLArguments (2.3.2)"
- GoogleUtilities/Environment (7.12.0):
- GoogleUtilities/Environment (7.13.0):
- GoogleUtilities/Privacy
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.12.0):
- GoogleUtilities/Logger (7.13.0):
- GoogleUtilities/Environment
- "GoogleUtilities/NSData+zlib (7.12.0)"
- GoogleUtilities/UserDefaults (7.12.0):
- GoogleUtilities/Privacy
- "GoogleUtilities/NSData+zlib (7.13.0)":
- GoogleUtilities/Privacy
- GoogleUtilities/Privacy (7.13.0)
- GoogleUtilities/UserDefaults (7.13.0):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- GoogleUtilitiesComponents (1.1.0):
- GoogleUtilities/Logger
- "gRPC-C++ (1.49.1)":
Expand Down Expand Up @@ -841,7 +846,7 @@ PODS:
- GTMSessionFetcher/Core (2.3.0)
- isar_flutter_libs (1.0.0):
- Flutter
- leveldb-library (1.22.3)
- leveldb-library (1.22.4)
- MLImage (1.0.0-beta4)
- MLKitBarcodeScanning (3.0.0):
- MLKitCommon (~> 9.0)
Expand Down Expand Up @@ -1012,13 +1017,13 @@ SPEC CHECKSUMS:
file_picker: 15fd9539e4eb735dc54bae8c0534a7a9511a03de
Firebase: 414ad272f8d02dfbf12662a9d43f4bba9bec2a06
firebase_core: 0af4a2b24f62071f9bf283691c0ee41556dcb3f5
FirebaseAppCheckInterop: 69fc7d8f6a1cbfa973efb8d1723651de30d12525
FirebaseAppCheckInterop: 58db3e9494751399cf3e7b7e3e705cff71099153
FirebaseCore: 2322423314d92f946219c8791674d2f3345b598f
FirebaseCoreExtension: 1c044fd46e95036cccb29134757c499613f3f564
FirebaseCoreInternal: 43c1788eaeee9d1b97caaa751af567ce11010d00
FirebaseCoreExtension: 6394c00b887d0bebadbc7049c464aa0cbddc5d41
FirebaseCoreInternal: bca337352024b18424a61e478460547d46c4c753
FirebaseFirestore: 171bcbb57a1a348dd171a0d5e382c03ef85a77bb
FirebaseFirestoreInternal: 7ac1e0c5b4e75aeb898dfe4b1d6d77abbac9eca3
FirebaseSharedSwift: 19b3f709993d6fa1d84941d41c01e3c4c11eab93
FirebaseFirestoreInternal: 86fe6fc8ca156309cb4842d2d7b2f15c669a64a0
FirebaseSharedSwift: 48076404e6e52372290d15a07d2ed1d2f1754023
fl_location: 68b4a6c4aad2a453493ff66f196e0748280cf43e
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_fgbg: 31c0d1140a131daea2d342121808f6aa0dcd879d
Expand All @@ -1027,18 +1032,18 @@ SPEC CHECKSUMS:
flutter_volume_controller: e4d5832f08008180f76e30faf671ffd5a425e529
fluttertoast: 31b00dabfa7fb7bacd9e7dbee580d7a2ff4bf265
google_sign_in_ios: 1bfaf6607b44cd1b24c4d4bc39719870440f9ce1
GoogleDataTransport: 57c22343ab29bc686febbf7cbb13bad167c2d8fe
GoogleDataTransport: bed3a36c04c8552479fbb9b76326e0fc69bddcb2
GoogleMLKit: 2bd0dc6253c4d4f227aad460f69215a504b2980e
GoogleSignIn: b232380cf495a429b8095d3178a8d5855b42e842
GoogleToolboxForMac: 8bef7c7c5cf7291c687cf5354f39f9db6399ad34
GoogleUtilities: 0759d1a57ebb953965c2dfe0ba4c82e95ccc2e34
GoogleUtilities: d053d902a8edaa9904e1bd00c37535385b8ed152
GoogleUtilitiesComponents: 679b2c881db3b615a2777504623df6122dd20afe
"gRPC-C++": 2df8cba576898bdacd29f0266d5236fa0e26ba6a
gRPC-Core: a21a60aefc08c68c247b439a9ef97174b0c54f96
GTMAppAuth: 99fb010047ba3973b7026e45393f51f27ab965ae
GTMSessionFetcher: 3a63d75eecd6aa32c2fc79f578064e1214dfdec2
isar_flutter_libs: b69f437aeab9c521821c3f376198c4371fa21073
leveldb-library: e74c27d8fbd22854db7cb467968a0b8aa1db7126
leveldb-library: 06a69cc7582d64b29424a63e085e683cc188230a
MLImage: 7bb7c4264164ade9bf64f679b40fb29c8f33ee9b
MLKitBarcodeScanning: 04e264482c5f3810cb89ebc134ef6b61e67db505
MLKitCommon: c1b791c3e667091918d91bda4bba69a91011e390
Expand All @@ -1057,6 +1062,6 @@ SPEC CHECKSUMS:
url_launcher_ios: bbd758c6e7f9fd7b5b1d4cde34d2b95fcce5e812
vibration: 7d883d141656a1c1a6d8d238616b2042a51a1241

PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048
PODFILE CHECKSUM: b0d4019d63a06aa0d701044dbc594a28e1b1d370

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
6 changes: 4 additions & 2 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
EE7366E14E5A260606CB06CD /* Pods-Runner.release.xcconfig */,
B33171C6E207358295CC5A05 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -160,7 +159,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -381,6 +380,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = A36HPZ86P4;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -509,6 +509,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = A36HPZ86P4;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -531,6 +532,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = A36HPZ86P4;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 3 additions & 1 deletion ios/Runner/Info.plist
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?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>
<dict>
<key>PermissionGroupNotification</key>
<string>This app needs notification permissions to show notifications.</string>
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to scan QR codes</string>
<key>NSPhotoLibraryUsageDescription</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,28 @@ class AddOrUpdateAlarmController extends GetxController {
onPressed: () async {
Get.back();

// Request overlay permission
if (!(await Permission.systemAlertWindow.isGranted)) {
final status = await Permission.systemAlertWindow.request();
if (!status.isGranted) {
debugPrint('SYSTEM_ALERT_WINDOW permission denied!');
return;
if (Platform.isAndroid) {
// Request overlay permission
if (!(await Permission.systemAlertWindow.isGranted)) {
final status = await Permission.systemAlertWindow.request();
if (!status.isGranted) {
debugPrint('SYSTEM_ALERT_WINDOW permission denied!');
return;
}
}
}

if (!(await Permission.ignoreBatteryOptimizations.isGranted)) {
bool requested = await Permission.ignoreBatteryOptimizations
.request()
.isGranted;
if (!requested) {
debugPrint('IGNORE_BATTERY_OPTIMIZATION permission denied!');
return;
if (!(await Permission.ignoreBatteryOptimizations.isGranted)) {
bool requested = await Permission.ignoreBatteryOptimizations
.request()
.isGranted;
if (!requested) {
debugPrint(
'IGNORE_BATTERY_OPTIMIZATION permission denied!');
return;
}
}
}

// Request notification permission
if (!await Permission.notification.isGranted) {
final status = await Permission.notification.request();
Expand Down

0 comments on commit bae50ea

Please sign in to comment.