nativescript-contacts icon indicating copy to clipboard operation
nativescript-contacts copied to clipboard

Unable to getAllContacts on iOS 13

Open fpaaske opened this issue 5 years ago • 5 comments

It seems that something is broken when using this library on iOS 13. The permission request pops up, and there are no error messages. But the response is always an empty list.

Same code on iOS 12 or below works fine.

To reproduce

tns create contacts-test --template tns-template-hello-world-ng
cd contacts-test
tns info
✔ Getting NativeScript components versions information...
✔ Component nativescript has 6.2.0 version and is up to date.
✔ Component tns-core-modules has 6.2.0 version and is up to date.
✔ Component tns-android has 6.2.0 version and is up to date.
✔ Component tns-ios has 6.2.0 version and is up to date.
yarn add nativescript-contacts

add to Info.plist:

<key>NSContactsUsageDescription</key>
<string>Kindly provide permission to access contact on your device.</string>

add to items.component.ts

import { getAllContacts } from "nativescript-contacts";
<snip>
    ngOnInit(): void {
        this.items = this.itemService.getItems();
        getAllContacts().then(contacts => console.log(`got ${contacts.data.length} contacts`));
    }

Open multiple emulators from iOS 10 to iOS 13.

tns run ios --emulator

See that contacts.data.length is 0 for iOS 13.

fpaaske avatar Nov 10 '19 23:11 fpaaske

@firescript do you know what could cause this issue, and if there's a workaround for iOS 13?

fpaaske avatar Nov 18 '19 13:11 fpaaske

ios 13 has introduced new entitlement for accessing contacts, see details at https://stackoverflow.com/questions/57442114/ios-13-cncontacts-no-longer-working-to-retrieve-all-contacts

liuy97 avatar Nov 21 '19 19:11 liuy97

@liuy97 you are absolutely right. Removing request for notes solves the issue. @firescript you should consider throwing some error with relevant information when this happens. Now it just fails silently.

fpaaske avatar Dec 04 '19 14:12 fpaaske

@mrpaaske Hello, can you say what exactly should i do to get the result in getAllContacts? I'm new in nativescript and mobile applications.

UPD: I got it, in getAllContacts we should pass array of fields. And don't ask for notes field. Example: .getAllContacts(['name', 'phoneNumbers'])

xaosaki avatar Jan 22 '20 13:01 xaosaki

@xaosaki that's exactly it 👍

fpaaske avatar Jan 23 '20 07:01 fpaaske