flutter-permission-handler
flutter-permission-handler copied to clipboard
[WIP] Add Swift Package Manager support
This PR relates to #1439
This pull request (PR) aims to implement Swift Package Manager (SPM) support while maintaining CocoaPods. It also tracks progress on streamlining the developer experience. This PR is open for discussion, welcoming new ideas and feedback on any issues or omissions.
I've implemented an SPM file and updated the podspec file to point to the new source files. I've also created the folder structure suggested by the Flutter team in their SPM migration article: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors#116-tab-panel.
To run the Example app with SPM, remove (or rename) the Podfile and execute pod deintegrate in the example app's iOS folder. Then, enable SPM in Flutter with flutter config --enable-swift-package-manager and execute flutter run with the following environment variable exports:
PERMISSION_EVENTS=1 PERMISSION_EVENTS_FULL_ACCESS=1 PERMISSION_REMINDERS=1 PERMISSION_CONTACTS=1 PERMISSION_CAMERA=1 PERMISSION_MICROPHONE=1 PERMISSION_SPEECH_RECOGNIZER=1 PERMISSION_PHOTOS=1 PERMISSION_LOCATION=1 PERMISSION_LOCATION_WHENINUSE=1 PERMISSION_NOTIFICATIONS=1 PERMISSION_MEDIA_LIBRARY=1 PERMISSION_SENSORS=1 PERMISSION_BLUETOOTH=1 PERMISSION_APP_TRACKING_TRANSPARENCY=1 PERMISSION_CRITICAL_ALERTS=1 PERMISSION_ASSISTANT=1 flutter run
I've chosen to activate permission modules through environment variables, similar to the approach described here: Conditionally compile code in a Flutter plugin using Swift Package Manager. This simplifies the process. A potential improvement is creating an xcconfig file containing the desired permissions as variables. This file could then be imported into the Release or Debug xcconfig files, making it a one-time setup and eliminating the need to export these variables for each run.
Here are some useful links with additional information:
- [SwiftPM] Support conditional compilation in plugins
- Swift Package Traits Feature Request
- Conditionally compile code in a Flutter plugin using Swift Package Manager
Pre-launch Checklist
- [x] I made sure the project builds.
- [ x I read the Contributor Guide and followed the process outlined there for submitting PRs.
- [ ] I updated
pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is does not need version changes. - [ ] I updated
CHANGELOG.mdto add a description of the change. - [ ] I updated/added relevant documentation (doc comments with
///). - [x] I rebased onto
main. - [ ] I added new tests to check the change I am making, or this PR does not need tests.
- [x] I made sure all existing and new tests are passing.
- [x] I ran
dart format .and committed any changes. - [x] I ran
flutter analyzeand fixed any errors.