区分外观联系人与IOS电话簿(联系人)

时间:2015-08-31 13:49:14

标签: iphone outlook contacts addressbook

我可以通过以下代码阅读手机联系人。它将阅读联系人的所有联系人,包括" OUTLOOK SYNC CONTACTS",

如何识别联系人是否来自Outlook?

如何区分同步联系人(outlook,gmail,wats应用程序联系人)与其他本地联系人?

    -(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");

    }
        }
}

请指导我

谢谢

Amith

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用MFCMAPI打开其中一个您不希望同步的联系人以及想要同步的联系人,以查看哪些内容具有显着差异?