iphone bring up address book contact - iphone

I am having some trouble accessing the iphone addressbook given a ABReferenceID.
The method is being called correctly (accessoryButtonTappedForRowWithIndexPath), all the #import stuff is fine (as I can save the data no problem).
I have a contact with ReferenceID = 69273024, I simply want to bring 'him up.
I am trying to do this with the following technique, but line 2 is wrong. I can't work out how to correctly integrate the number into the problem. Any tips?
ABPersonViewController *pvc = [[ABPersonViewController alloc] init];
pvc.displayedPerson = 69273024;
[[self navigationController] pushViewController:pvc animated:YES];
Regards, norskben.

The displayedPerson property should be set to an ABRecordRef. You can get the ABRecordRef from the ABRecordID using ABAddressBookGetPersonWithRecordID. You can get the ABAddressBookRef using ABAddressBookCreate.
UPDATE
Here is example code, but I haven't tested it:
ABPersonViewController *pvc = [[ABPersonViewController alloc] init];
pvc.displayedPerson = ABAddressBookGetPersonWithRecordID(ABAddressBookCreate(),69273024);
[[self navigationController] pushViewController:pvc animated:YES];
[pvc release];

Related

how to show particular selected person contact form Address Book Ui Iphone?

I am implementing address book Ui in my application. And I am getting some problem.
I have a record id and i want to show details of that contact form address book UI frame work.
For that I have used this code:-
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
ABAddressBookRef addressBook = ABAddressBookCreate( );
NSNumber *recordId = [NSNumber numberWithInteger:[record_str integerValue]];
ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook,recordId.integerValue);
[self peoplePickerNavigationController:picker shouldContinueAfterSelectingPerson:person];
[self presentModalViewController:picker animated:YES];
[picker release];
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
return YES;}
When I run the code then it show all contact list while I have display only given record.
How can I show the address of the person whom i choose from picker?
Thanks in advance....
I have made a mistake that is I am calling ABPeoplePickerNavigationController instead of ABPersonViewController. So that it showing whole contact list instead of particular contact.
Thanks to all to visit this question.

Sending an email through app; any way will do

Here is the code that I have for my cell of my UITableView:
forKeys:[NSArray arrayWithObjects:#"Title", #"Cells", #"Footer Title", nil]] autorelease];
[tableView1CellData addObject:sectionContainer_3];
NSMutableArray *cells_4 = [[[NSMutableArray alloc] init] autorelease];
NSDictionary *cellContainer_4_1 = [[[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:#"Support", #"", #"", #"", #"", #"1", nil]
What would I have to add so that when the cell is tapped, it happened up a MailView in the app (preferably) but I understand that the easiest way is to just use the HTML "mailto" ? I'm brand new to Objective-C, but I am able to edit C and C++, so I think that I can work in any answer. Thanks in advance!
P.S. Posting this from iPhone (just thought of asking question) so sorry if the code isn't highlighted, but i tried to space it out.
Check out the documentation on MFMailComposeViewController. You can present a mail compose view, user will fill it out and send the mail.
1.Add the Message UI Framework
2.You should have registered a delegate for the UITableView. See a UITableView tutorial if needed.
3.Implement the following method:
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
...
}
4.Inside the method use MFMailComposeViewController to send the email. Example usage:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"My Subject"];
[controller setMessageBody:#"Hello there." isHTML:NO];
if (controller) [self presentModalViewController:controller animated:YES];
[controller release];
Read More: How can I send mail from an iPhone application
UITableView/UITableViewCell tap event response?
And yes, you can use the mailto: URL thing... but #jer's answer is the one I would prefer to do myself, as a developer.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"mailto://info#iosdevelopertips.com"]];
(details for the above can be found at http://iosdevelopertips.com/cocoa/launching-other-apps-within-an-iphone-application.html)

Send SMS iPhone

I was trying to send SMS from within my app. I wrote this piece of code but it seems not to work.
No crash, no error log, simply nothing happen (of course I tried to log canSendText and the result is 1).
- (void)viewDidLoad
{
[super viewDidLoad];
messageComposer = [[MFMessageComposeViewController alloc] init];
if ([MFMessageComposeViewController canSendText]) {
[messageComposer setBody:#"Messaggio generato da SMSTest"];
[messageComposer setRecipients:[NSArray arrayWithObject:#"3333333333"]];
[messageComposer setDelegate:self];
[self presentModalViewController:messageComposer animated:YES];
}
}
Can anyone explain me what I'm doing wrong?
The problem is that presentModalViewController does not work in viewDidLoad yet as the view is loaded but might not even be on screen yet. If you put your code in viewWillAppear:animated, this should work.
Edit: As per Saphrosit's comment: viewDidAppear: is an even better place to do this.
I use this successfully:
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.messageComposeDelegate = self;
controller.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:controller animated:YES];
Note that it's messageComposeDelegate, not 'delegate' as you do.
Tim
When i try the code on simulator i get an UIAlert saying text messaging is not available, because simulator canĀ“t send messages. Have you checked that your header file is a delegate of MFMessageComposeViewControllerDelegate ?
YourClassName : UIViewController <MFMessageComposeViewControllerDelegate>
//try this ... it will run ..
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"Hello from Kartik";
controller.recipients = [NSArray arrayWithObjects:#"12356478", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}

MFMailComposer Exec_bad_access - might it have something to do with initialization

In a view controller i have a button which internally calls an IBAction and that internally calls the
[self showEmailModalView:FinalEmail];
now ... in the showEmailModalView i have
-(void) showEmailModalView:(NSString *)email{
MFMailComposeViewController *mvc =[[[MFMailComposeViewController alloc] init]autorelease];
mvc.mailComposeDelegate = self;
NSArray *mails = [[NSArray arrayWithObject:email]autorelease];
[mvc setToRecipients:mails];
NSString*emailBody =[NSString stringWithFormat:#" "];
[mvc setMessageBody:emailBody isHTML:YES];
mvc.navigationBar.barStyle = UIBarStyleBlack;
[[self navigationController] presentModalViewController:mvc animated:YES];
}
and then
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[[self navigationController] dismissModalViewControllerAnimated:YES];
}
Now it works alright... for all the scenarios of email or delete or anything like that but right after completion of the code the simulator just throws a exec_bad_access and then does nothing.... can you help.
PS: i also found out that that when ever you are giving a release to the mvc as declared above the error is called. ant thoughts.
Update:
I did install the app with only one change... i initialized the mvc in the header file and then just use the same statement. so now i am not getting the exec_bad_access errors anymore... i think it was frightened of the nsZOMBIES....Haha... thanks for your Help and support.. guys... Both of you....
You shouldn't autorelease this object, it's already autoreleased :
NSArray *mails = [[NSArray arrayWithObject:email ]autorelease];
Instead of change to:
NSArray *mails = [NSArray arrayWithObject:email];

Sending sms programmatically code Problem

I am writing code to send sms programatically
Program crashes at second last line.
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObject:#"123456789"]; // your recipient number or self for testing
picker.body = #"test from OS4";
[self presentModalViewController:picker animated:YES];
[picker release];
I assume it's safe to say that it implements
UIViewController <MFMessageComposeViewControllerDelegate>
In which case, I would recommend going back to http://iphonesdkdev.blogspot.com/2010/04/mfmessagecomposeviewcontroller-sample.html, copying their example and progressing from there.