0

I can read the phone contacts by the following code.It will read all the contacts from contacts including "OUTLOOK SYNC CONTACTS",

How can i identify if the contacts came from outlook or not?

or

How can i differentiate sync contacts (outlook,gmail,wats app contacts) from other local contacts?

    -(void) getLocalPhContacts{
    @autoreleasepool {
        NSMutableArray *arr = [[NSMutableArray alloc] init];

    ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
        ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
            //ABAddressBookRef addressBook = ABAddressBookCreate();
        });
    }
    else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {

        CFErrorRef *error = NULL;
        ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
        CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
        CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);


        for(int i = 0; i < numberOfPeople; i++) {

            PhoneContactEntry *phEntry = [[PhoneContactEntry alloc] init];

            ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );

            NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
            NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
        NSString *property = (__bridge NSString *)(ABRecordCopyValue(person, kABSourceType));
       VELog(@"property:  %@ name=%@",property ,firstName);
           NSString *lName=(lastName!=nil && [lastName length]>0)?lastName:@"";
            NSString *name= [NSString stringWithFormat:@"%@ %@",firstName,lName];
            [phEntry setName:name];

            ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
            [[UIDevice currentDevice] name];

            //VELog(@"\n%@\n", [[UIDevice currentDevice] name]);

            for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
                NSString *phoneNumber = (__bridge_transfer NSString *) ABMultiValueCopyValueAtIndex(phoneNumbers, i);
                if(i==0){
                    [phEntry setNumber:phoneNumber];
                }
                [phEntry addNumber:phoneNumber];
                //addressBookNum = [addressBookNum stringByAppendingFormat: @":%@",phoneNumber];
                VELog(@"   ph number   %@",phoneNumber);
//                NSString *complete = [NSString stringWithFormat:@"%@ %@ %@", firstName,
//                                      lastName,phoneNumber];

            }
             [arr addObject:phEntry];
        }
        //  VELog(@"AllNumber:%@",addressBookNum);
         [self saveToDb:arr];
    }
    else {
        VELog(@"Send an alert telling user to change privacy setting in settings app");

    }
        }
}

Please guide me

Thanks

Amith

Amith
  • 1,907
  • 5
  • 29
  • 48

1 Answers1

0

Have you tried using MFCMAPI to open one of the contacts you don't want to sync alongside one you do want to sync to see what, if anything, stands out as a significant difference?

sgriffin
  • 337
  • 1
  • 9