Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5980653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:49:54+00:00 2026-05-22T21:49:54+00:00

This issue is something which has me stumped, so hopefully someone can help. I

  • 0

This issue is something which has me stumped, so hopefully someone can help. I have an UIActionSheet on a view which has three options in. One which takes my user to a new view, one to share via email and one to share via SMS.

I have the UIActionSheet created which works without issue, the new view part of the AlertSheet also works. I have imported the Message.UI framework and set up the mail and SMS pickers and composers which are fine. However, I am having trouble setting the two ‘buttons’ on the UIActionSheet to open up the mail and SMS.

Normally i would do this through interface builder and connect a UIButton to the actions I have created, but because this is a UIActionSheet it can’t be done that way. Sorry for the LONG code but I felt I needed to show everything, so please see below;

-(IBAction)showActionSheet {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose an Option" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Application Support",@"Share Via Email",@"Share Via SMS",nil];
    [actionSheet showInView:self.view];
    [actionSheet release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex == 0) {
    AppSupportView *controller = [[AppSupportView alloc] initWithNibName:@"AppSupportView" bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
    [controller release];
    }

    if(buttonIndex == 1) {

    }

    if(buttonIndex == 2) {

    }

}

- (void)dealloc {
    [feedbackMsg release];
    [super dealloc];
}

- (void)viewDidUnload {
    self.feedbackMsg = nil;
}

-(IBAction)showMailPicker:(id)sender {
    // The MFMailComposeViewController class is only available in iPhone OS 3.0 or later. 
    // So, we must verify the existence of the above class and provide a workaround for devices running 
    // earlier versions of the iPhone OS. 
    // We display an email composition interface if MFMailComposeViewController exists and the device 
    // can send emails. Display feedback message, otherwise.
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));

    if (mailClass != nil) {
        //[self displayMailComposerSheet];
        // We must always check whether the current device is configured for sending emails
        if ([mailClass canSendMail]) {
            [self displayMailComposerSheet];
        }
        else {
            feedbackMsg.hidden = NO;
            feedbackMsg.text = @"Device not configured to send mail.";
        }
    }
    else    {
        feedbackMsg.hidden = NO;
        feedbackMsg.text = @"Device not configured to send mail.";
    }
}

-(IBAction)showSMSPicker:(id)sender {
    //  The MFMessageComposeViewController class is only available in iPhone OS 4.0 or later. 
    //  So, we must verify the existence of the above class and log an error message for devices
    //      running earlier versions of the iPhone OS. Set feedbackMsg if device doesn't support 
    //      MFMessageComposeViewController API.
    Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

    if (messageClass != nil) {          
        // Check whether the current device is configured for sending SMS messages
        if ([messageClass canSendText]) {
            [self displaySMSComposerSheet];
        }
        else {  
            feedbackMsg.hidden = NO;
            feedbackMsg.text = @"Device not configured to send SMS.";

        }
    }
    else {
        feedbackMsg.hidden = NO;
        feedbackMsg.text = @"Device not configured to send SMS.";
    }
}

// Displays an email composition interface inside the application. Populates all the Mail fields. 
-(void)displayMailComposerSheet 
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"My BMR Index Rating from Total:Health App"];


    // Set up recipients
    //NSArray *toRecipients = [NSArray arrayWithObject:@""]; 

     //[picker setToRecipients:toRecipients];
    NSString *emailSharing = @"I Just discovered that I have a Target Heart Rate of";
    // Fill out the email body text
    [picker setMessageBody:emailSharing isHTML:YES];

    [self presentModalViewController:picker animated:YES];
    [picker release];
}

// Displays an SMS composition interface inside the application. 
-(void)displaySMSComposerSheet 
{
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
    picker.messageComposeDelegate = self;
    NSString *SMSShare = @"I Just discovered that I have a Target Heart Rate of";
    // Fill out the email body text
    picker.body = SMSShare;

    [self presentModalViewController:picker animated:YES];
    [picker release];
}

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the 
// message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller 
          didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {

    feedbackMsg.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            feedbackMsg.text = @"Result: Mail sending canceled";
            break;
        case MFMailComposeResultSaved:
            feedbackMsg.text = @"Result: Mail saved";
            break;
        case MFMailComposeResultSent:
            feedbackMsg.text = @"Result: Mail sent";
            break;
        case MFMailComposeResultFailed:
            feedbackMsg.text = @"Result: Mail sending failed";
            break;
        default:
            feedbackMsg.text = @"Result: Mail not sent";
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}


// Dismisses the message composition interface when users tap Cancel or Send. Proceeds to update the 
// feedback message field with the result of the operation.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
                 didFinishWithResult:(MessageComposeResult)result {

    feedbackMsg.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MessageComposeResultCancelled:
            feedbackMsg.text = @"Result: SMS sending canceled";
            break;
        case MessageComposeResultSent:
            feedbackMsg.text = @"Result: SMS sent";
            break;
        case MessageComposeResultFailed:
            feedbackMsg.text = @"Result: SMS sending failed";
            break;
        default:
            feedbackMsg.text = @"Result: SMS not sent";
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}

@end

The issue is obviously that I dont know how to proceed with the (if buttonIndex ==1) etc piece of code to open the mail and SMS

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex == 0) {
    AppSupportView *controller = [[AppSupportView alloc] initWithNibName:@"AppSupportView" bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
    [controller release];
    }

    if(buttonIndex == 1) {

    }

    if(buttonIndex == 2) {

    }

}

Any help would be appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:49:55+00:00Added an answer on May 22, 2026 at 9:49 pm

    looks like all your needed methods are there already..
    just add [self showMailPicker:nil] or [self showSMSPicker:nil] to

    if(buttonIndex == 1) {
    
    }
    
    if(buttonIndex == 2) {
    
    }
    

    if your second button from the top is your sms button, add showSMSPicker to buttonIndex == 1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone come across this issue? Seems MS have broken it with their own
Hey all. Something which has been bugging me quite a bit recently is this
Am I doing something wrong is this a known issue with the ASP.NET MVC
Now I must be missing something here, as this seems a very basic issue
This issue is driving me mad. I have several tables defined, and CRUD stored
I am running into this issue of releasing an already released object but can't
I do not currently have this issue , but you never know, and thought
A quick Google search of this issue shows it's common, I just can't for
I'm relatively(read: stupid newbie) familiar with disassembly but this bit stumped me: I have
I have spent 3 days & 4 SO questions trying to fix something which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.