Closed IbrahimCanKALYA closed 3 years ago
me too
I managed to fix this problem.
import React, { useEffect, useState } from 'react'`
> `import Contacts from 'react-native-contacts';`
> `import { PermissionsAndroid } from 'react-native';`
>
> ...
> ` const [contacts, setContacts] = useState<any>([])`
>
> `async function hasAndroidPermission() {`
> `const permission = PermissionsAndroid.PERMISSIONS.READ_CONTACTS;`
> `const hasPermission = await PermissionsAndroid.check(permission);`
> ` if (hasPermission) {`
> `return true;`
> `}`
> `const status = await PermissionsAndroid.request(permission);`
> `return status === 'granted';`
> ` }`
>
> `const loadContacts = async () => {`
> ` if (await hasAndroidPermission()) {`
> `Contacts.getAll().then(contacts => {`
> ` setContacts(contacts)`
> `})`
> `}`
> `return`
> `};`
>
> `useEffect(() => {`
> `hasAndroidPermission()`
> `}, [])`
>
> `useEffect(() => {`
> ` loadContacts()`
> `}, [hasAndroidPermission])`
Hello! anyone raising PR for this?
nope. @mayank-budhiraja would you like to write the PR?
This issue is stale, please provide more information about the status
@gabrieloureiro what is the issue?
Faced similar issue. When trying to get the contacts using the provided example, the app was crashing as soon as I request for the permission.
After countless hours of findings, this was the only answer which helped, (app got crashed after allowing the read permission, but didn't crash after) https://github.com/morenoh149/react-native-contacts/issues/549#issuecomment-691893482
Couldn't read row 900, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. com.rt2zz.reactnativecontacts.ContactsProvider.loadContactsFrom
Device Info: Brand: Xiaomi Model: Mi A1 Operating System Version: 9 Rooted: No
react-native: 0.62.2 react-native-contacts: 6.0.4
I faced with this crash & i couldn't find any solution or wrong usage of library.
thanks in advance