简体   繁体   中英

open iphone Mail from Actionsheet

I want to open Mail app from my app when the one button in actionsheet is pressed, I know this way :

 -(IBAtion)openClick:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:foo@example.com"]];
}

but can I write this method inside if statement or switch case ?(in ControlView class NOT NSObject class , because I use actionsheet for this propose)

like this:

     - (void)actionSheet:(UIActionSheet *)modalView clickedButtonAtIndex:(NSInteger)buttonIndex
{


switch (buttonIndex)
{
    case 0:
    {

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”mailto:foo@example.com”]];
        break;
    }

I can't test my code because simulator doesn't have the Mail app.. So I need to know is this will work in controlView or must write it in NSObject class ?

+ seconde question : I want to open Mail app from my app and copy the content in the view to mail body,then the user choice the contact from his contacts list ! Is this way achieve my goal?

Why not use MFMailComposeViewController ? Then the user won't need to quit your app to send a mail, and you can set the body content more easily, and you can test it on simulator.


Your code will work (after fixing the smart quotes).

To set the content of the mail body, use mailto:abc@example.com?body=The%20Body . See http://www.ianr.unl.edu/internet/mailto.html for the syntax of mailto: .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM