Skip to content

Conversation

@zenixio
Copy link

@zenixio zenixio commented Jan 4, 2026

Issue
IOS permission request state not being reset when app enters background, causing subsequent requests to fail with ERROR_ALREADY_REQUESTING_PERMISSIONS.

Video : https://github.com/user-attachments/assets/0f78390a-cbd3-4362-87c8-2874ae4ac620

Changes:

  • Added background notification observer to reset state in PermissionHandlerPlugin.m
  • Properly cleanup observer in dealloc

Reproduction Steps (Before Fix)

  1. Call await Permission.location.request()
  2. When iOS system permission dialog appears, block screen
  3. Return to app
  4. Call await Permission.location.request() again
  5. Result: Exception thrown: ERROR_ALREADY_REQUESTING_PERMISSIONS

Expected Behavior

If the app is backgrounded during a permission request:

  • The pending Flutter callback should be completed with an error (REQUEST_INTERRUPTED)
  • The internal state should be reset (_methodResult = nil)
  • Subsequent permission requests should work normally without throwing ERROR_ALREADY_REQUESTING_PERMISSIONS
  • The user should be able to retry the permission request when they return to the app

Actual Behavior (Before Fix)

  • The pending Flutter callback is never completed (Future hangs indefinitely)
  • The internal state remains set (_methodResult != nil)
  • All subsequent permission requests immediately fail with ERROR_ALREADY_REQUESTING_PERMISSIONS
  • The app becomes unusable for any permission-related functionality until restarted

Solution

  • Register observer for UIApplicationDidEnterBackgroundNotification when plugin initializes
  • When app backgrounds with a pending request, complete the Flutter callback with REQUEST_INTERRUPTED error and reset internal state

After Fix

Same reproduction steps now work correctly:

  1. Call await Permission.location.request()
  2. Block Screen → App backgrounds
  3. Return to app
  4. Call await Permission.location.request() again
  5. Result: New permission request works normally, dialog appears again

Pre-launch Checklist

  • I made sure the project builds.
  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is does not need version changes.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I rebased onto main.
  • I added new tests to check the change I am making, or this PR does not need tests.
  • I made sure all existing and new tests are passing.
  • I ran dart format . and committed any changes.
  • I ran flutter analyze and fixed any errors.

Drago Picari and others added 3 commits January 4, 2026 16:00
@zenixio
Copy link
Author

zenixio commented Jan 5, 2026

hi @mvanbeusekom could you please check this one ?

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.

1 participant