firescript / nativescript-contacts

A nativescript module that gives access to the native contact directory.
MIT License
28 stars 32 forks source link

Unable to getAllContacts on iOS 13 #79

Open fpaaske opened 5 years ago

fpaaske commented 5 years ago

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 commented 5 years ago

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

liuy97 commented 5 years ago

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

fpaaske commented 4 years ago

@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.

xaosaki commented 4 years ago

@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'])

fpaaske commented 4 years ago

@xaosaki that's exactly it 👍