React-native-contacts: Contacts.getAll works on emulator but crashes on mobile phone.

Created on 31 Mar 2018  路  10Comments  路  Source: morenoh149/react-native-contacts

Here is my code:


import React from 'react'
import { View, Text } from 'react-native'
import Contacts from 'react-native-contacts'

export default class ContactTab extends React.Component {

    componentDidMount() {

        console.log("Hello", Contacts)

        Contacts.getAll((err, contacts) => {
            console.log("dude")
        })
    }

    render() {
        return (
            <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
                <Text>Settings!</Text>
            </View>
        )
    }
}

It works fine on emulator but crashes on phone.

The crash report only says

I/ReactNativeJS(19364): 'Hello', { addContact: { [Function: fn] type: 'async' },
I/ReactNativeJS(19364):   checkPermission: { [Function: fn] type: 'async' },
I/ReactNativeJS(19364):   getAll: { [Function: fn] type: 'async' },
I/ReactNativeJS(19364):   getAllWithoutPhotos: { [Function: fn] type: 'async' },
I/ReactNativeJS(19364):   getContactsMatchingString: { [Function: fn] type: 'async' },
I/ReactNativeJS(19364):   getPhotoForId: { [Function: fn] type: 'async' },
I/ReactNativeJS(19364):   openContactForm: { [Function: fn] type: 'async' },
I/ReactNativeJS(19364):   requestPermission: { [Function: fn] type: 'async' },
I/ReactNativeJS(19364):   updateContact: { [Function: fn] type: 'async' } }
D/ReactNative(19364): ReactInstanceManager.detachViewFromInstance()

As the Contacts.getAll function gets called app crashed.

What might be the issue ? I checked the permission and it returns "authorized".

Any solution to this ?

bug

Most helpful comment

@morenoh149 Here is what I have commented
nrc

All 10 comments

i get same error

The issue was from getting birthday from contacts in react-native-contact. I simply uncommented the else block that was doing logic for birthday and it works fine.

Everything was working fine in my emulator but for my mobile the code inside the else if block was not working and raising error. I tried formatting the birthday code without double hiphen too but it didnt worked either so I commented the whole else if block, as I was not neeeding birthday from contacts.

As it was working fine on my emulator, I looked at the response but it was not giving birthday in the response. I dont know if it returns empty if not birthday or the birthday key will not be provided in the response.

if you share exactly what lines you commented out it would narrow down my investigation @aaeronn

@morenoh149 I think @aaeronn means that he commented the whole block which parses birthday :)

We encountered the same issue today, one of our customers on Galaxy S7 has a contact record with the birthday "1972. 1. 15.". Will comment this block for now too.

As a possible solution it might worse to wrap each block into try/catch, because for most of the apps it's better to skip some field than crash.

JFYI, I searched for similar issues and there are possible formats for START_DATE
From https://stackoverflow.com/questions/5106722/android-event-start-date-format:

  • TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
  • REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
  • INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

Other possible formats mentioned by developers:

  • "Jun 12, 1985"
  • "1972. 1. 15."

@morenoh149 Here is what I have commented
nrc

Do we need to edit node modules ?

@faizalshap yes you need to edit in node modules

Was this page helpful?
0 / 5 - 0 ratings