- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
// setting the first name
NSString *fname = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
// setting the last name
NSString *lname = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *mail=(__bridge NSString*)ABRecordCopyValue(person, kABPersonEmailProperty);
//NSString *mobile=(__bridge NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *pNo = (__bridge NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
NSLog(@"LLname%@",lname);
NSLog(@"fLname%@",fname);
NSLog(@"mobile%@",pNo);
NSLog(@"mail%@",mail);
if([fname isEqualToString:@""] || fname == nil)
{
UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:nil message:@"Please enter first name." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", @"") otherButtonTitles:nil];
[locationAlert show];
// return;
}
else if([lname isEqualToString:@""]|| lname == nil)
{
UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:nil message:@"Please enter last name." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", @"") otherButtonTitles:nil];
[locationAlert show];
//return;
}
else if([pNo isEqualToString:@""]|| pNo == nil)
{
UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:nil message:@"Please enter mobile no." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", @"") otherButtonTitles:nil];
[locationAlert show];
// return;
}
else if([mail isEqualToString:@""] || mail == nil)
{
UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:nil message:@"Please enter email address." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", @"") otherButtonTitles:nil];
[locationAlert show];
//return;
}
else
{
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
CFStringRef email = ABMultiValueCopyValueAtIndex(emails, 0);
NSLog(@"email %@\n",(__bridge NSString *) email);
// setting the number
/*
this function will set the first number it finds
if you do not set a number for a contact it will probably
crash
*/
NSString *mNo = pNo;
mNo=[mNo stringByReplacingOccurrencesOfString:@"(" withString:@""];
mNo=[mNo stringByReplacingOccurrencesOfString:@")" withString:@""];
mNo=[mNo stringByReplacingOccurrencesOfString:@" " withString:@""];
mNo=[mNo stringByReplacingOccurrencesOfString:@"-" withString:@""];
// NSLog(@"mno %@\n",mNo);
NSString *name = [fname stringByAppendingFormat:[NSString stringWithFormat:@" %@",lname]];
[clist setValue:mNo forKey:name];
// NSLog(@"dic %@\n",clist);
// [allcontactArray addObject:name];
// [contactList addObject:(NSArray *)allcontactArray];
[contacts addObject:name];
// NSLog(@"contacts %@\n",contacts);
// NSLog(@"str %@\n",[clist objectForKey:name]);
[contactArr addObject:name];
[contactDic setObject:mNo forKey:name];
// NSLog(@"arr: %@\n",contactArr);
// NSLog(@"dic: %@\n",contactDic);
contactname = name;
[contactStr appendFormat:@"%@, ",name];
// NSLog(@"contactstr: %@\n",contactStr);
// NSLog(@"mno %@\n",mNo);
[phoneNoArray addObject:mNo];
[phoneStr appendFormat:@"%@=",mNo];
// NSLog(@"phonearr: %@\n",phoneNoArray);
// NSLog(@"phonestr: %@\n",phoneStr);
tf.text = contactStr;
// remove the controller
[self dismissModalViewControllerAnimated:YES];
return NO;
}
}
このオープンソースを使用してiphoneから連絡先をインポートしています。名または姓または携帯電話番号またはメールアドレスが空の場合にアプリがクラッシュします。名義名と姓名が空かどうかを確認できます。携帯電話番号とメールアドレスを確認できません。お願いします。この問題を解決するのに役立ちます。