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

[iOS] Unable to delete contact #87

Open
fpaaske opened this issue Jul 28, 2020 · 3 comments
Open

[iOS] Unable to delete contact #87

fpaaske opened this issue Jul 28, 2020 · 3 comments

Comments

@fpaaske
Copy link

fpaaske commented Jul 28, 2020

I do this:

const response = await NativeScriptContacts.getAllContacts(['name']);
console.log('response.response', response.response);
console.log('response.data', response.data.length);
let first = response.data[0];
console.log('first contact', first);
first.delete();

And I get this error:

ERROR Error: Uncaught (in promise): TypeError: null is not an object (evaluating 'foundContacts.count')

Full output:

CONSOLE LOG file: src/app/contacts/contacts.component.ts:65:20: response.response fetch
CONSOLE LOG file: src/app/contacts/contacts.component.ts:66:20: response.data 1361
CONSOLE LOG file: src/app/contacts/contacts.component.ts:68:20: first contact {
"id": "50A1444F-B134-41E1-98AE-DECF64D3B1B2",
"name": {
"given": "Some guy",
"middle": "",
"family": "",
"prefix": "",
"suffix": "",
"displayname": "",
"phonetic": {
"given": "",
"middle": "",
"family": ""
}
},
"organization": {
"name": "",
"jobTitle": "",
"department": ""
},
"nickname": "",
"notes": "",
"photo": null,
"urls": [],
"phoneNumbers": [],
"emailAddresses": [],
"postalAddresses": []
}
CONSOLE ERROR file: node_modules/@angular/core/fesm5/core.js:4002:0: ERROR Error: Uncaught (in promise): TypeError: null is not an object (evaluating 'foundContacts.count')
tns info
✔ Getting NativeScript components versions information...
✔ Component nativescript has 6.7.8 version and is up to date.
✔ Component tns-core-modules has 6.5.12 version and is up to date.
✔ Component tns-android has 6.5.3 version and is up to date.
✔ Component tns-ios has 6.5.2 version and is up to date.
@fpaaske
Copy link
Author

fpaaske commented Jul 28, 2020

This may be related to #77

@dlcole
Copy link
Contributor

dlcole commented Feb 12, 2021

I'm hitting the same thing in a JavaScript project

tns info
✔ Getting NativeScript components versions information...
⚠ Update available for component nativescript. Your current version is 6.8.0 and the latest available version is 7.2.0.
⚠ Update available for component tns-core-modules. Your current version is 6.5.24 and the latest available version is 6.5.25.
✔ Component tns-android has 6.5.3 version and is up to date.
✔ Component tns-ios has 6.5.4 version and is up to date.

@dlcole
Copy link
Contributor

dlcole commented Feb 12, 2021

I did some debugging, and the code at issue is contact-model.ios.js line 251:

var foundContacts = store.unifiedContactsMatchingPredicateKeysToFetchError(searchPredicate, keysToFetch, null);
if (foundContacts.count > 0) {
    contactRecord = foundContacts[0].mutableCopy();
 }

foundContacts is null, and so foundContacts.count raises an exception.

if (foundContacts && foundContacts.count > 0) {

It's not clear yet why store.unifiedContactsMatchingPredicateKeysToFetchError is returning null.

[edit]

I've been investigating further, as I really need this to work. I tried replacing unifiedContactsMatchingPredicateKeysToFetchError with unifiedContactWithIdentifierKeysToFetchError but with no luck. Both functions take a third parameter which the doc simply describes as, "Error information, if an error occurred." but I haven't found anyway to catch the error data, even within a try/catch block.

If anyone knows how to catch the error data that would certainly help.

[edit 2]

This post looks pertinent. I'll investigate later today.

[edit 3]

Here's what's changed: com.apple.developer.contacts.notes

Apple has made access to the notes field more restricted. If I comment-out "note" from keysToFetch, the contact.delete() works as expected. Next I'll figure out how I want to proceed with this. I don't really need the notes field, and that may mean I'll locally modify my own copy of the plugin to remove it from keysToFetch.

[edit 4]

This issue is a dupe of #89, and fixed with pull request #90.

[edit 5]

Correction: while issue #89 does address a similar issue, pr #90 does not include changes to contact-model.ios.js, and thus does not fix this particular issue. To bypass the issue it is sufficient to comment out line 244 ("note",) in keysToFetch.

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

No branches or pull requests

2 participants