From 7527e616683d9edb4784a77f7a815a4456f9aba9 Mon Sep 17 00:00:00 2001 From: DonovanOng Date: Thu, 23 Jun 2016 11:01:37 +0800 Subject: [PATCH 1/2] Add Company and Job Title --- ios/RCTContacts/RCTContacts.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ios/RCTContacts/RCTContacts.m b/ios/RCTContacts/RCTContacts.m index 4046d599..4acdfe13 100644 --- a/ios/RCTContacts/RCTContacts.m +++ b/ios/RCTContacts/RCTContacts.m @@ -88,6 +88,8 @@ -(NSDictionary*) dictionaryRepresentationForABPerson:(ABRecordRef) person NSString *givenName = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty)); NSString *familyName = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty)); NSString *middleName = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonMiddleNameProperty)); + NSString *company = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonCompanyProperty)); + NSString *jobTitle = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonJobTitleProperty)); [contact setObject: recordID forKey: @"recordID"]; @@ -106,6 +108,14 @@ -(NSDictionary*) dictionaryRepresentationForABPerson:(ABRecordRef) person [contact setObject: (middleName) ? middleName : @"" forKey:@"middleName"]; } + if(company){ + [contact setObject: (company) ? company : @"" forKey:@"company"]; + } + + if(jobTitle){ + [contact setObject: (jobTitle) ? jobTitle : @"" forKey:@"jobTitle"]; + } + if(!hasName){ //nameless contact, do not include in results return nil; @@ -182,7 +192,7 @@ -(NSString *) getABPersonThumbnailFilepath:(ABRecordRef) person tempfilePath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:template length:strlen(template)]; - + tempfilePath = [tempfilePath stringByAppendingString:@".png"]; [data writeToFile:tempfilePath options:NSAtomicWrite error:&err]; @@ -221,9 +231,13 @@ -(void) updateRecord:(ABRecordRef)record onAddressBook:(ABAddressBookRef)address NSString *givenName = [contactData valueForKey:@"givenName"]; NSString *familyName = [contactData valueForKey:@"familyName"]; NSString *middleName = [contactData valueForKey:@"middleName"]; + NSString *company = [contactData valueForKey:@"company"]; + NSString *jobTitle = [contactData valueForKey:@"jobTitle"]; ABRecordSetValue(record, kABPersonFirstNameProperty, (__bridge CFStringRef) givenName, &error); ABRecordSetValue(record, kABPersonLastNameProperty, (__bridge CFStringRef) familyName, &error); ABRecordSetValue(record, kABPersonMiddleNameProperty, (__bridge CFStringRef) middleName, &error); + ABRecordSetValue(record, kABPersonCompanyProperty, (__bridge CFStringRef) company, &error); + ABRecordSetValue(record, kABPersonJobTitleProperty, (__bridge CFStringRef) jobTitle, &error); ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType); NSArray* phoneNumbers = [contactData valueForKey:@"phoneNumbers"]; From 287525ca6d686f2e29743718c884991fe9a7ec06 Mon Sep 17 00:00:00 2001 From: DonovanOng Date: Thu, 23 Jun 2016 11:20:30 +0800 Subject: [PATCH 2/2] Use correct kABPersonOrganizationProperty --- ios/RCTContacts/RCTContacts.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/RCTContacts/RCTContacts.m b/ios/RCTContacts/RCTContacts.m index 4acdfe13..a399feb4 100644 --- a/ios/RCTContacts/RCTContacts.m +++ b/ios/RCTContacts/RCTContacts.m @@ -88,7 +88,7 @@ -(NSDictionary*) dictionaryRepresentationForABPerson:(ABRecordRef) person NSString *givenName = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty)); NSString *familyName = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty)); NSString *middleName = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonMiddleNameProperty)); - NSString *company = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonCompanyProperty)); + NSString *company = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonOrganizationProperty)); NSString *jobTitle = (__bridge_transfer NSString *)(ABRecordCopyValue(person, kABPersonJobTitleProperty)); [contact setObject: recordID forKey: @"recordID"]; @@ -236,7 +236,7 @@ -(void) updateRecord:(ABRecordRef)record onAddressBook:(ABAddressBookRef)address ABRecordSetValue(record, kABPersonFirstNameProperty, (__bridge CFStringRef) givenName, &error); ABRecordSetValue(record, kABPersonLastNameProperty, (__bridge CFStringRef) familyName, &error); ABRecordSetValue(record, kABPersonMiddleNameProperty, (__bridge CFStringRef) middleName, &error); - ABRecordSetValue(record, kABPersonCompanyProperty, (__bridge CFStringRef) company, &error); + ABRecordSetValue(record, kABPersonOrganizationProperty, (__bridge CFStringRef) company, &error); ABRecordSetValue(record, kABPersonJobTitleProperty, (__bridge CFStringRef) jobTitle, &error); ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);