Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Pyro2b

macrumors newbie
Original poster
Aug 2, 2004
28
0
California
Hi, I am new at this, and have been struggling through app development. I have a problem with some of my code. The user can choose a person's phone number in my app, and the phone number is inserted into a field. I need the phone number to be inserted into the field with no formatting. Basically like: 2123453423 instead of how is is currently being inserted like: (212) 345-3423. If anyone has suggestions as to how I can get my code to work, I'd be very appreciative. Here is what I have so far:

Code:
- (IBAction) adressBook: (id) sender; {
	ABPeoplePickerNavigationController *pp = [[ABPeoplePickerNavigationController alloc] init];
	pp.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]];
	pp.peoplePickerDelegate = self;
	[self presentModalViewController:pp animated:YES];
	[pp release];
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
    // assigning control back to the main controller
	[self dismissModalViewControllerAnimated:YES];
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
	return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
	
	ABMultiValueRef phoneProperty = ABRecordCopyValue(person,property);
	NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty,identifier);
		
	 [[[[phone stringByReplacingOccurrencesOfString:@"(" withString:@""]
				  stringByReplacingOccurrencesOfString:@")" withString:@""]
				 stringByReplacingOccurrencesOfString:@"-" withString:@""]
				stringByReplacingOccurrencesOfString:@" " withString:@""];
		
	
	phonenumber.text = phone;
	
	[phone release];
	
	[self dismissModalViewControllerAnimated:YES];
	return NO;
}

Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.