Skip to content

Dismiss the iOS native editor when the contact is deleted from it - #249

Open
liliana-tagonsoft wants to merge 1 commit into
QuisApp:mainfrom
liliana-tagonsoft:fix/ios-editor-dismiss-on-delete
Open

Dismiss the iOS native editor when the contact is deleted from it#249
liliana-tagonsoft wants to merge 1 commit into
QuisApp:mainfrom
liliana-tagonsoft:fix/ios-editor-dismiss-on-delete

Conversation

@liliana-tagonsoft

@liliana-tagonsoft liliana-tagonsoft commented Aug 27, 2026

Copy link
Copy Markdown

Description

On iOS, FlutterContacts.native.showEditor(contactId) presents a CNContactViewController with
allowsEditing = true. Tapping the editor's Delete Contact row deletes the contact, but:

  • contactViewController(_:didCompleteWith:) is never called, so the sheet stays on screen with a
    now-deleted contact still rendered in it;
  • the showEditor Future doesn't complete until the user closes the sheet by hand — the controller
    is presented in editing mode, so it shows its own ✕ / ✓ items rather than the injected Done
    button — and it then resolves to null, indistinguishable from "cancelled", so the app has no way
    to know the contact was deleted;
  • calling showEditor again for the same id then throws
    PlatformException(flutter_contacts_error, Updated Record Does Not Exist), because
    store.unifiedContact(withIdentifier:) fails on the deleted identifier.

Note the Delete Contact row only appears in a third-party CNContactViewController on iOS 26+
(it isn't offered on earlier versions), which is probably why this hasn't come up before.

Fix

While the editor is presented, observe .CNContactStoreDidChange. When a store change arrives and
unifiedContact(withIdentifier:) no longer returns the edited contact, dismiss the editor and
complete the pending result with nil. The dismissal goes through
navController.presentingViewController so the delete confirmation sheet, if it's still animating
out, goes away with the editor. The observer is removed in completeWithResult, so it's torn down
on every exit path (delegate, close, deletion).

Saves are unaffected: the notification also fires on a normal edit, but the contact still resolves,
so the observer returns early and the existing delegate path handles it.

Testing

Tested in a production app on the iOS 26.3 simulator (iPhone 17 Pro):

  • Editor → Delete Contact → confirm: the sheet now dismisses itself and showEditor completes
    with null.
  • Editor → edit a field → save: unchanged, completes with the contact identifier.
  • Editor → close without changes: unchanged, completes with null.

Notes

showEditor still returns null for both "cancelled" and "deleted". Distinguishing them would need
an API change (e.g. a sentinel or a richer result), so this PR keeps the signature and just fixes
the stuck sheet — happy to follow up with that if you'd like it.

CNContactViewController's "Delete Contact" row never calls
contactViewController(_:didCompleteWith:), so showEditor's sheet stays on
screen and its Future never completes. Observe CNContactStoreDidChange
while the editor is up and close it once the edited contact is gone.
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