Skip to content

feat(apple): add Swift Package Manager support#1523

Open
TheoGermain wants to merge 17 commits intoBaseflow:mainfrom
TheoGermain:feat/spm-support
Open

feat(apple): add Swift Package Manager support#1523
TheoGermain wants to merge 17 commits intoBaseflow:mainfrom
TheoGermain:feat/spm-support

Conversation

@TheoGermain
Copy link
Copy Markdown

@TheoGermain TheoGermain commented May 5, 2026

cc @TimHoogstrate for review.

Summary

  • Adds Package.swift to permission_handler_apple/ios/permission_handler_apple/ for Swift Package Manager compatibility (Flutter 3.24+)
  • Moves ObjC sources from ios/Classes/ to ios/permission_handler_apple/Sources/permission_handler_apple/ (SPM-standard layout)
  • Updates podspec to reference new source paths — CocoaPods remains fully supported with no changes required from existing users
  • Permission auto-detection via Info.plist: Package.swift walks up the directory tree to find the app's Info.plist and enables each PERMISSION_X define when the corresponding usage description key is present. No additional configuration needed beyond what is already required for permissions to work at runtime.
  • PermissionGroup.notification and PermissionGroup.criticalAlerts (no required Info.plist key) are still configurable via environment variable
  • Updates iOS deployment target from 8.0 to 12.0 for consistency with Package.swift

Supersedes the work started in #1440.
Closes #1439
Closes #1516

Permission defines (SPM)

Permissions activate automatically when the usage description key is present in Info.plist:

Permission group Info.plist key
calendar (< iOS 17) NSCalendarsUsageDescription
calendarFullAccess (iOS 17+) NSCalendarsFullAccessUsageDescription
reminders NSRemindersUsageDescription
contacts NSContactsUsageDescription
camera NSCameraUsageDescription
microphone NSMicrophoneUsageDescription
speech NSSpeechRecognitionUsageDescription
photos NSPhotoLibraryUsageDescription
photosAddOnly NSPhotoLibraryAddUsageDescription
location / locationWhenInUse NSLocationWhenInUseUsageDescription
locationAlways NSLocationAlwaysAndWhenInUseUsageDescription
mediaLibrary NSAppleMusicUsageDescription
sensors NSMotionUsageDescription
bluetooth NSBluetoothAlwaysUsageDescription
appTrackingTransparency NSUserTrackingUsageDescription
assistant NSSiriUsageDescription

notification and criticalAlerts require launchctl setenv PERMISSION_NOTIFICATIONS 1 (no Info.plist key required by iOS).

After adding or removing a key, clear DerivedData once: rm -rf ~/Library/Developer/Xcode/DerivedData

Test plan

  • swift package dump-package validates Package.swift syntax
  • CocoaPods installation verified (pod install succeeds on example app)
  • All Flutter unit tests pass (20/20)
  • End-to-end build with SPM enabled in Xcode — flutter build ios --no-codesign passes
  • Permission dialogs appear for permissions declared in Info.plist (camera, microphone verified)
  • Removing a key from Info.plist + clearing DerivedData disables the permission (no dialog, returns permanentlyDenied)

Notes

@vicajilau
Copy link
Copy Markdown

@TheoGermain, should the file docs/superpowers/plans/2026-05-05-spm-support.md be deleted?

Package.swift now walks up the directory tree from its own location to find
the app's Info.plist and enables each permission define when the corresponding
usage description key is present. This mirrors the CocoaPods workflow: adding
NSCameraUsageDescription to Info.plist is all that is needed to activate
PERMISSION_CAMERA, with no extra configuration files or terminal commands.

Environment variables remain supported as an explicit override (priority over
Info.plist), which covers PermissionGroup.notification and criticalAlerts that
have no required Info.plist key.

Users must clear DerivedData once after changing Info.plist so Xcode
re-evaluates the manifest: rm -rf ~/Library/Developer/Xcode/DerivedData
Replace the launchctl setenv / pre-action script approach with the new
Info.plist-based mechanism: permissions are now enabled automatically when
the corresponding usage description key is present in Info.plist, which is
already required for any permission to work at runtime.

Document the two permissions without an Info.plist key (notification,
criticalAlerts) as the only case still requiring an env var.
- Add all permission usage description keys to Info.plist so the SPM
  Info.plist auto-detection covers all permissions out of the box
- Comment out the Siri entitlement (requires a paid Apple Developer
  account; uncomment to test PERMISSION_ASSISTANT)
- Update AppDelegate to modern FlutterImplicitEngineDelegate pattern
- Bump Podfile iOS platform to 13.0
- Remove docs/superpowers/plans/2026-05-05-spm-support.md (internal
  planning artifact not intended for the public repo)
@TheoGermain
Copy link
Copy Markdown
Author

TheoGermain commented May 6, 2026

Good catch, thanks! The file has been removed in the latest commit, it was an internal planning artifact that shouldn't have been included.

@TheoGermain TheoGermain mentioned this pull request May 6, 2026
4 tasks
Comment on lines +5 to +6
<!--
Uncomment to test PERMISSION_ASSISTANT (requires a paid Apple Developer account):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to keep this in

Copy link
Copy Markdown

@CanadianN1nj4 CanadianN1nj4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super great work on this! I'm sure making sure everything still worked with cocoapods and transitioning was a good amount of effort!

Great Readme's too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add SPM Support [Enhancement proposal]: [WIP] Add Swift Package Manager support

3 participants