Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlatformException on contact update #95

Open
yassinsameh opened this issue Feb 3, 2023 · 5 comments
Open

PlatformException on contact update #95

yassinsameh opened this issue Feb 3, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@yassinsameh
Copy link

yassinsameh commented Feb 3, 2023

Generally the update method is working correctly for most users, when viewing crashlytics logs however i find this error coming up for more than one user.

Unable to have any more information, could you please provide any insight on how to get more information or the cause of this? @joachimvalente @joachim-quis

Error: PlatformException(unknown error, unknown error, The operation couldn’t be completed. (CNErrorDomain error 2.), null). Error thrown null.

Stacktrace:

0  ???                            0x0 StandardMethodCodec.decodeEnvelope + 653 (message_codecs.dart:653)
1  ???                            0x0 MethodChannel._invokeMethod + 296 (platform_channel.dart:296)
2  ???                            0x0 FlutterContacts.updateContact + 189 (flutter_contacts.dart:189)

flutter_contacts: 1.1.5+1

@yassinsameh yassinsameh changed the title Crash on contact update PlatformException on contact update Feb 4, 2023
@yassinsameh
Copy link
Author

yassinsameh commented Feb 5, 2023

Another form of the error: PlatformException(unknown error, unknown error, Violated Constraints Error, null). Error thrown null.

@yassinsameh
Copy link
Author

yassinsameh commented Feb 6, 2023

The only similar issue i could find is here: https://stackoverflow.com/questions/33033163/cncontactstore-executesaverequest-failing-with-cnerrordomain-error-2

It recommends not setting the fields as empty array unless the contact has objects for that certain attribute.

So to follow up on that, I would have 2 questions:

  1. In the package why is it that in the addFieldsToContact method, all args such as args["emails"] is assumed to never be null.
  2. Does it make sense to change all variables to the following syntax (Checks for null and only sets item to empty array first if it doesn't exist in args, and that would result in removing the clearFieldsMethod which sets to empty array in all cases)

This:

if let websites = args["websites"] as? [[String: Any]], !websites.isEmpty {
            contact.urlAddresses = []
            websites.forEach {
                Website(fromMap: $0).addTo(contact)
            }
        }

Instead of this:

(args["websites"] as! [[String: Any]]).forEach {
            Website(fromMap: $0).addTo(contact)
        }

@scroollocker @anggrayudi @jadasi @joachimvalente

@joachim-quis
Copy link
Contributor

Hi @yassinsameh, thanks for reporting and looking into this. This suggestion makes a lot of sense. Did it fix your issue? If so, I'll add it to the next version.

@joachim-quis joachim-quis added the bug Something isn't working label Feb 9, 2023
@yassinsameh
Copy link
Author

Hi @joachim-quis , after the changes outlined i no longer get the "CNErrorDomain error 2" , I still do get the "Violated constraints error" Which i believe is caused by Read-Only contacts attempting to be updated, is there a way we can add that boolean field in the Flutter Contact so developers can be aware of this to not attempt updating?

@yassinsameh
Copy link
Author

@joachim-quis following up on this, any idea how we can detect if it is read only and add that boolean to the Contact object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants