Pages

Saturday, September 10, 2011

Add Custom Label in Default Contact Application

To Add custom label in Default contact, we can try below code.


CFErrorRef error = NULL;
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
ABRecordRef newPerson = ABPersonCreate();
const CFStringRef customLabel = CFSTR( "Nir" );

//phone
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, @"CUSTOM LABEL", customLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
ABAddressBookSave(iPhoneAddressBook, &error);
ABAddressBookRemoveRecord(iPhoneAddressBook, newPerson, &error);
ABAddressBookSave(iPhoneAddressBook, &error);
if (error != NULL)
{
NSLog(@"Error!");
}

THANKS................

Remove Characters from String


Remove Character set form string:


NSString *strPhone = @"54564-6556-6-65(113)";

NSCharacterSet *charactersToRemove =[[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];

strPhone = [[strPhone componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString:@""];

NSLog(@"%@",strPhone);

Result : Get 545646556665113 by removing -,( and ) from string

NSString *strPhone = @"54564-6556-6-65(113)";

NSCharacterSet *charactersToRemove =[NSCharacterSet characterSetWithCharactersInString:@"0123456789"];

strPhone = [[strPhone componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString:@""];

NSLog(@"%@",strPhone);

Result : Get --() by removing all entry of 0123456789


thanks
Happpppyyyyyyy Pro.....................


Saturday, June 25, 2011

Iphone:Trimming whitespace characters from NSString



If you need to trim whitespace characters at the start and end of a NSString, here’s an easy way:

existingStr = [ existingStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ;

iphone:Rotate UI Component.

We can rotate UI component through CGAffineTransformMakeRotation such as.
Rotate Button:
btn.transform = CGAffineTransformMakeRotation(0.15);

Rotate Label:
lbl.transform = CGAffineTransformMakeRotation(0.15);