How do I initate an email on the iphone from a view? - iphone

I need to be able to give users the ability to call someone or email someone from a certain view in my navigation based app.
I thought I would use an action sheet with the choices and depending on the button pressed allow one or the other to be initiated (I'm simplifying a lot but ...).
I really have several questions.
Assuming this is possible to do, will my app be gone after a phone call is started?
Is there a way for me to launch/push on the stack the same "controller" and "view" that Apple uses for making calls and sending emails? Or am I going to have to code this all myself to look like their app?
I want the user to come back to the same page they were on when the email or phone call was initiated. How can I do that or is my app gone if I use their controller and nib?
Assuming it's possible to do either of these things, can I put the email address I want for a default in the to: field of the email view and if so how?

Here are the answers to your questions:
Assuming this is possible to do, will
my app be gone after a phone call is
started?
Yes.
Is there a way for me to launch/push
on the stack the same "controller"
and "view" that Apple uses for making
calls and sending emails? Or am I
going to have to code this all myself
to look like their app?
Yes. MFMailComposeViewController for Mail, and [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telephoneText]] for a Call
I want the user to come back to the
same page they were on when the email
or phone call was initiated. How can
I do that or is my app gone if I use
their controller and nib?
For Mail this can be accomplished with MFMailComposeViewController. It's not possible for a telephone Call.
Assuming it's possible to do either
of these things, can I put the email
address I want for a default in the
to: field of the email view and if so
how?
Yes.
You can look at the sample code https://developer.apple.com/iphone/library/samplecode/MailComposer/index.html or the tutorial http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email

unfortunately if you make a phone call then the application is terminated. For email however, I believe there is a framework or something to do that, I think it's in the messaging API, but I'm not 100% sure as whenever I use email stuff I just do a mailto: url (which closes the app)

You can not make a phone call from within you application without exiting your app.
You can send an email inside your application using MFMailComposeViewController. Your application will remain at whatever view it was at when you present the Mail Compose View Controller view. You can set all of the normal fields in an email (subject, recipients, cc, bcc, body, ect...).

Related

Is there a way to prevent MFMailComposeViewController from sending an email?

I use an MFMailComposeViewController in an app to make it easy for the user to send me support requests. However, I get a lot of emails with the default message (+ the user's signature), but without any additional info added. I'm guessing this is because a kid is using the device and they're just mashing buttons. Is there any way to detect this case and have it not send the email?
Unfortunately, this is not possible.
From the apple docs:
Important: The mail composition interface itself is not customizable
and must not be modified by your application. In addition, after
presenting the interface, your application is not allowed to make
further changes to the email content. The user may still edit the
content using the interface, but programmatic changes are ignored.
Thus, you must set the values of content fields before presenting the
interface.

iOS ABPersonViewController: Returning to app after phone call/message/email

I'm using an ABPersonViewController and I was wondering if it is possible to return to my application after making a phone call or sending an email/message instead of exiting to the respective native apps.
On the iPhone Contacts app, you can make a phone call by pressing the phone number field. Ending the call automatically takes you back to the contact screen. You can also send an email and message by clicking on the respective fields (though ending the email/message action does not take you back to the Contacts).
To be more specific, tapping on "mobile 1 (555) 555-5559" should make a phone call to that number (my app already does that). However, when I end the call, I would like to be directed back to my app and not the native iOS Phone app. I would like similar actions for sending an email and message too.
If this is possible, it would be great if someone could share the solution! Thanks for any help.
it is possible to return to my application after making a phone call or sending an email/message instead of exiting to the respective native apps.
AND
Ending the call automatically takes you back to the contact screen
In SHORT : It is not possible because Apple/iOS Does not Provide this type of Feature.

Sending mail in background

I am developing an iphone application in which i have to send a mail on custom button click and in background also it should not have user iteraction with mfmailcomposer view i.e, i dont have to show the view.
Please suggest me solution for this.
Thanks.
You could try using SKSMTPMessage:
http://code.google.com/p/skpsmtpmessage/
You won't be able to use the user's email accounts unless you ask them to provide credentials, but I've used this a few times where the sender address is not important.
The easiest solution for this problem is,
You need to create your own webservice. Pass all the details to your webservice and accordingly send email.
Details to be passed on webservice would be to/cc/bcc/subject/body etc.

iPhone: How to disable editing when MFMessageComposeViewController shows up

Is it possible to prevent editing when MFMessageComposeViewController shows up?
'Cause I want the body of SMS can't be changed by user and I think it's still legal.
Please help!
No the user has final say when using the MFMessageComposeView.
Your app is also prohibited from changing the content/recipient/body of the email when the
view slides up.
If you could do this it would be easy to paste in a different recipient, sniff the content provided by the user etc. etc. (especially in the Message App, you could swap the phone number and do terrible things.).
I guess this is the logic behind, you get to pre-populate the message, but the user decides from there on and until "Cancel" or "Send".
You should probably build a web service where you have control over the data
when it hits the server and make an interface for that on the phone.

How to activate mail application (built in in iPhone) through programming? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I send mail from an iPhone application
how to activate mail application (built in in iphone) through programming. I want to quit
my project also?
I can't really be sure by the wording of your question, but it seems like you want to send mail without leaving your application.
In the 3.0 SDK you have access to MFMailComposeViewController, which will bring up a mail window and allow you to send mail while remaining in your application.
From the Apple Docs:
The MFMailComposeViewController class provides a standard interface that manages the editing and sending an email message. You can use this view controller to display a standard email view inside your application and populate the fields of that view with initial values, such as the subject, email recipients, body text, and attachments. The user can edit the initial contents you specify and choose to send the email or cancel the operation.
Using this interface does not guarantee immediate delivery of the corresponding email message. The user may cancel the creation of the message, and if the user does choose to send the message, the message is only queued in the Mail application outbox. This allows you to generate emails even in situations where the user does not have network access, such as in airplane mode. This interface does not provide a way for you to verify whether emails were actually sent.
Before using this class, you must always check to see if the current device is configured to send email at all using the canSendMail method. If the user’s device is not set up for the delivery of email, you can notify the user or simply disable the email dispatch features in your application. You should not attempt to use this interface if the canSendMail method returns NO.
To display the view managed by this view controller, you can use any of the standard techniques for displaying view controllers. However, the most common way to present this interface is do so modally using the presentModalViewController:animated: method. Figure 1 shows the view that is displayed when you present the mail composition interface, with some of the fields already filled in. For more information on displaying the views associated with view controllers, see View Controller Programming Guide for iPhone OS.
Something similar to:
NSString *_recipient = #"someone#email.com";
NSURL *_mailURL = [NSURL URLWithString:[NSString stringWithFormat:#"mailto:%#?subject=My Subject", _recipient]];
[[UIApplication sharedApplication] openURL:_mailURL];
will open the Mail app and create a new message with the subject "My Subject" and the recipient someone#email.com. Just modify this with other headers and content to build the message you need to send.
This is how you can send mail from the iphone app.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"mailto:biranchi#purpletalk.com?cc=youremail#gmail.com&subject=Greetings%20from%20Biranchi!&body=Wish%20you%20were%20here!"]];
If you don't want to quit your app:
iphone app send email