Skip to content

Commit

Permalink
Merge pull request #109 from nimblehq/feature/101-add-permission-handler
Browse files Browse the repository at this point in the history
[#101] Add permission handler to request app permissions
  • Loading branch information
luongvo authored Dec 28, 2022
2 parents d2b0be4 + 05c5877 commit 1a42048
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 21 deletions.
58 changes: 56 additions & 2 deletions .template/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def flutter_root
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
Expand All @@ -30,12 +30,66 @@ flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
# TODO You can enable the permissions needed here.
# permission, just remove the `#` character in front so it looks like this:
#
# ## dart: PermissionGroup.camera
#'PERMISSION_CAMERA=1'
#
# Preprocessor definitions can be found in: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',

## dart: PermissionGroup.calendar
# 'PERMISSION_EVENTS=1',

## dart: PermissionGroup.reminders
# 'PERMISSION_REMINDERS=1',

## dart: PermissionGroup.contacts
# 'PERMISSION_CONTACTS=1',

## dart: PermissionGroup.camera
# 'PERMISSION_CAMERA=1',

## dart: PermissionGroup.microphone
# 'PERMISSION_MICROPHONE=1',

## dart: PermissionGroup.speech
# 'PERMISSION_SPEECH_RECOGNIZER=1',

## dart: PermissionGroup.photos
# 'PERMISSION_PHOTOS=1',

## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
# 'PERMISSION_LOCATION=1',

## dart: PermissionGroup.notification
# 'PERMISSION_NOTIFICATIONS=1',

## dart: PermissionGroup.mediaLibrary
# 'PERMISSION_MEDIA_LIBRARY=1',

## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=1',

## dart: PermissionGroup.bluetooth
# 'PERMISSION_BLUETOOTH=1',

## dart: PermissionGroup.appTrackingTransparency
# 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

## dart: PermissionGroup.criticalAlerts
# 'PERMISSION_CRITICAL_ALERTS=1'
]
end
end
end
10 changes: 8 additions & 2 deletions .template/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ PODS:
- Flutter
- package_info_plus (0.4.5):
- Flutter
- "permission_handler (5.1.0+2)":
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_config (from `.symlinks/plugins/flutter_config/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- permission_handler (from `.symlinks/plugins/permission_handler/ios`)

EXTERNAL SOURCES:
Flutter:
Expand All @@ -22,13 +25,16 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/integration_test/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
permission_handler:
:path: ".symlinks/plugins/permission_handler/ios"

SPEC CHECKSUMS:
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_config: 2226c1df19c78fe34a05eb7f1363445f18e76fc1
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
permission_handler: ccb20a9fad0ee9b1314a52b70b76b473c5f8dab0

PODFILE CHECKSUM: a75497545d4391e2d394c3668e20cfb1c2bbd4aa
PODFILE CHECKSUM: de482529810d31c8802b6be0fd93c8c3e038be64

COCOAPODS: 1.11.3
31 changes: 31 additions & 0 deletions .template/lib/utils/wrappers/permission_wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:injectable/injectable.dart';
import 'package:permission_handler/permission_handler.dart'
as permission_handler;

abstract class PermissionWrapper {
Future<bool> requestCameraPermission();

Future<bool> isCameraPermissionDenied();

Future<bool> isCameraPermissionPermanentlyDenied();
}

@Singleton(as: PermissionWrapper)
class PermissionWrapperImpl extends PermissionWrapper {
@override
Future<bool> requestCameraPermission() {
return permission_handler.Permission.camera
.request()
.then((value) => value == permission_handler.PermissionStatus.granted);
}

@override
Future<bool> isCameraPermissionDenied() {
return permission_handler.Permission.camera.isDenied;
}

@override
Future<bool> isCameraPermissionPermanentlyDenied() {
return permission_handler.Permission.camera.isPermanentlyDenied;
}
}
48 changes: 31 additions & 17 deletions .template/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ packages:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.11"
version: "3.3.0"
args:
dependency: transitive
description:
Expand All @@ -35,7 +35,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -105,7 +105,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
charcode:
dependency: transitive
description:
Expand All @@ -126,7 +126,7 @@ packages:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
code_builder:
dependency: transitive
description:
Expand Down Expand Up @@ -161,7 +161,7 @@ packages:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
version: "3.0.2"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -196,7 +196,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -399,21 +399,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -483,7 +483,21 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "8.3.0"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.9.0"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -593,7 +607,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -621,28 +635,28 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
sync_http:
dependency: transitive
description:
name: sync_http
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.3.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
time:
dependency: transitive
description:
Expand Down Expand Up @@ -670,7 +684,7 @@ packages:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
vector_math:
dependency: transitive
description:
Expand All @@ -684,7 +698,7 @@ packages:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "8.2.2"
version: "9.0.0"
watcher:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions .template/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies:
intl: ^0.17.0
json_annotation: ^4.5.0
package_info_plus: ^1.4.2
permission_handler: ^8.3.0
retrofit: ^3.0.1+1

dev_dependencies:
Expand Down

0 comments on commit 1a42048

Please sign in to comment.