0
我可以閱讀以下code.It手機通訊錄會從通訊錄中包括「Outlook同步聯繫人」讀取所有的聯繫人,微分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