react-native-contacts: iOS 13 - Contacts.getAll returns empty array

After upgrading XCode to 11-beta and launching my app on simulator with iOS 13 - Contacts.getAll returns an empty array, on iOS 12 I had an array with contacts. Contacts permissions are granted to application

import Contacts from 'react-native-contacts';
const contacts = 
yield new Promise((resolve, reject) => {
      Contacts.getAll((err, result) => {
        console.log('err', err);               //  ----> null
        console.log('result', result);     //  ----> [] on iOS 13; array with contacts on iOS 12
        return !err ? resolve(result) : reject(err)
      });
    });

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 16 (5 by maintainers)

Most upvoted comments

@morenoh149 You misunderstood me. I am not asking you to do anything with my fork, that was just an easy way out for any users that struggle with this issue (not everyone can just upgrade RN 🙂).

What I meant to say is that all that is needed to do is to create release 4.0.3 of RNC, which would be based on release 4.0.2, just with cherry-picked commit from version 5.0.4 (the commit which fixes this issue). This will provide support for RN<0.60, because currently the library itself is unusable for those versions on iOS 13.

As I said, I am happy to contribute to fix this problem, but this is not something that has to do with coding, just with maintaining the library. You can basically do this just by running these commands:

$ git checkout 4.0.2
$ git cherry-pick 02db1fef8200eeb26f1e1362ccd93baca772e0bf
$ npm version patch
$ npm publish

And 🎉, you just published 4.0.3 that is available to anyone with RN under 0.60.

@Olovorr nice. I followed your instructions. I think if anyone is on a legacy rn version they could find this issue and get the fix. I know not everyone can update their rn but sometimes its good to get pressure to update your deps.

For future reference, if ppl want fixes and things like that, submit the PRs and tell me what commands to run to publish bugfixes to older versions.

I found temporary solution.

According to information about iOS 13 - it deprecated access to “Notes” key from contacts - in a reason of security: https://techcrunch.com/2019/06/05/with-ios-13-apple-locks-out-apps-from-accessing-users-private-notes-in-contacts/

I tried to remove all “notes” references from RCTContacts.m from RCTContacts.xcodeproj library and it seems started working. I`ve created patch for react-native-contacts module:

--- a/node_modules/react-native-contacts/ios/RCTContacts/RCTContacts.m
+++ b/node_modules/react-native-contacts/ios/RCTContacts/RCTContacts.m
@@ -63,7 +63,6 @@ -(void) getContactsFromAddressBook:(CNContactStore *)store
                       CNContactOrganizationNameKey,
                       CNContactJobTitleKey,
                       CNContactImageDataAvailableKey,
-                      CNContactNoteKey,
                       CNContactUrlAddressesKey,
                       CNContactBirthdayKey
                       ];
@@ -118,7 +117,6 @@ -(void) retrieveContactsFromAddressBook:(CNContactStore*)contactStore
                                        CNContactOrganizationNameKey,
                                        CNContactJobTitleKey,
                                        CNContactImageDataAvailableKey,
-                                       CNContactNoteKey,
                                        CNContactUrlAddressesKey,
                                        CNContactBirthdayKey
                                        ]];
@@ -147,7 +145,6 @@ -(NSDictionary*) contactToDictionary:(CNContact *) person
     NSString *middleName = person.middleName;
     NSString *company = person.organizationName;
     NSString *jobTitle = person.jobTitle;
-    NSString *note = person.note;
     NSDateComponents *birthday = person.birthday;
     
     [output setObject:recordID forKey: @"recordID"];
@@ -172,10 +169,6 @@ -(NSDictionary*) contactToDictionary:(CNContact *) person
         [output setObject: (jobTitle) ? jobTitle : @"" forKey:@"jobTitle"];
     }
 
-    if(note){
-        [output setObject: (note) ? note : @"" forKey:@"note"];
-    }
-
     if (birthday) {
         if (birthday.month != NSDateComponentUndefined && birthday.day != NSDateComponentUndefined) {
             //months are indexed to 0 in JavaScript (0 = January) so we subtract 1 from NSDateComponents.month
@@ -457,7 +450,6 @@ - (void)contactViewController:(CNContactViewController *)viewController didCompl
                              CNContactImageDataAvailableKey,
                              CNContactThumbnailImageDataKey,
                              CNContactImageDataKey,
-                             CNContactNoteKey,
                              CNContactUrlAddressesKey,
                              CNContactBirthdayKey
                              ];
@@ -486,7 +478,6 @@ -(void) updateRecord:(CNMutableContact *)contact withData:(NSDictionary *)contac
     NSString *middleName = [contactData valueForKey:@"middleName"];
     NSString *company = [contactData valueForKey:@"company"];
     NSString *jobTitle = [contactData valueForKey:@"jobTitle"];
-    NSString *note = [contactData valueForKey:@"note"];
 
     NSDictionary *birthday = [contactData valueForKey:@"birthday"];
     
@@ -495,7 +486,6 @@ -(void) updateRecord:(CNMutableContact *)contact withData:(NSDictionary *)contac
     contact.middleName = middleName;
     contact.organizationName = company;
     contact.jobTitle = jobTitle;
-    contact.note = note;
     
     if (birthday) {
         NSDateComponents *components;

@ttDemon install rnc 4.0.3

@morenoh149 Hope you are interested in projects RN under 0.60. I really couldn’t upgrade my project. I am using RN 0.59x

@pmarconi yep. update your project to rn 60 first then use the latest rnc.