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)
});
});
Yes I can confirm that i have the exact some problem, iOS 13, returns empty list
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;
Thank you @vahutson 馃憤
I confirm that this indeed fixes the problem
Please submit the patch as a PR. I guess iOS will no longer return notes and Android will.
Hi @morenoh149 , I see that this patch was introduced in master branch, so that means that it is on [email protected] version and the documentation says:
If you are using rn 0.59 and below install rnc versions 4.x instead.
Right now my app it's using RN 0.59.x, so if I am understanding correctly if I use react-native-contacts@5 I will not be able to make it work on Android and if use version react-native-contacts@4 I will not able to get the contacts on iOS (since iOS 13), that's correct?
@pmarconi yep. update your project to rn 60 first then use the latest rnc.
@morenoh149 And wouldn't it be possible to create 4.0.3 release with this fixed? It is just matter of checking out to the 4.0.2 tag, create new branch, cherry-pick the commit which fixes this issue and release under 4.0.3 version 馃
I created fork where I did this for our org (and now we install it from the github instead of NPM), but I feel like this should be done on library level. I am happy to help, but I don't have access to publish new version to NPM (obviously), and there is not any coding to do here, just putting few commands into terminal.
For people looking for simple solution for RN 0.59.10 and below include:
"react-native-contacts": "webscopeio/react-native-contacts#4.0.3",
in your package.json; hence making this fix available for versions <0.60.
See the code itself at https://github.com/webscopeio/react-native-contacts/tree/4.0.3;
you should upgrade your rn. That is the real issue. I don't have the manpower to maintain forks for you.
@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.
@morenoh149 Hope you are interested in projects RN under 0.60. I really couldn't upgrade my project. I am using RN 0.59x
@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.
@morenoh149 @Olovorr So now I need to do something to fix the error on my project, please guide me, thanks
@ttDemon install rnc 4.0.3
@morenoh149 Thanks a lot for this, and good job! 馃檪Sure, I will submit PR just with the steps in the future 馃檪
Most helpful comment
@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:
And 馃帀, you just published 4.0.3 that is available to anyone with RN under 0.60.