how can i access iphone contacts from my app?
-
07-03-2021 - |
Question
I want to send a SMS from my application. For that,i use MFMessageComposeViewController
and "messageui.framework" and is working greatly. But for that i gave the number of receiver in code. Actually,i want to add contact from phonebook. How can i get the desired contact in my application at the time of sending sms using MFMessageComposeViewController
?
Suppose my code is below and i dont understand how can i give contact number from my contacts in picker.recipients.Please help me as i want to select the contact number from contacts to send sms from my application.
-(void)ComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObject:@"1234567890"];
picker.body = @"I am at %@";
[self presentModalViewController:picker animated:YES];
[picker release];
}
Solution 2
When we are using MFMessageComposeViewController
, then it automatically gives the link of contacts. So no need of AddressBookUI
Framework required in this case. In MFMessagecomposeViewController
, contacts have to be added by clicking the "+" button on the right side of the add recipients field.
OTHER TIPS
There are two frameworks for this. Address Book UI gives you some views to use. http://developer.apple.com/library/ios/#documentation/AddressBookUI/Reference/AddressBookUI_Framework/_index.html
Address Book doesn't, but it still gives you programmatic access to the address book. http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/AddressBook_iPhoneOS_Framework/_index.html#//apple_ref/doc/uid/TP40007212