1

I have been working on implementing SMS messaging into my app. Unfortunately whenever I test it I always get the default result, even if it does send the message and I receive it on the other end. What am I doing wrong, I have compared other examples and mine looks the same. Does this work with iMessage??? Now I am always getting it as sent, even if I go into text messaging and it will say failed.

// feedback message field with the result of the operation.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
             didFinishWithResult:(MessageComposeResult)result {

    switch (result)
    {
        case MFMailComposeResultCancelled:          

            [self displayStickieUniversalViewControllerTitleString:@"Cancelled" bodyString:@"You cancelled sending the SMS.The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3];

            break;
        case MFMailComposeResultSent:

            [self displayStickieUniversalViewControllerTitleString:@"SMS sent" bodyString:@"Your SMS was sent. The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3];

            break;
        case MFMailComposeResultFailed:
            [self displayStickieUniversalViewControllerTitleString:@"Failed" bodyString:@"Failed to send SMS. The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3];

            break;
        default:
            [self displayStickieUniversalViewControllerTitleString:@"Failed" bodyString:@"Failed to send SMS. The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3];      
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}

/////

 if (actionClicked == @"smsEvent") {
    if ([attendeesArray count]!=0) {
        NSLog(@"Yes clicked, will send sms confirmation");
        Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

        if (messageClass != nil) {          
            if ([messageClass canSendText]) {
                [self displaySMSComposerSheet];
            }
            else {  

                 [self displayStickieUniversalViewControllerTitleString:@"Device not configured to send SMS." bodyString:@"The event will be saved in the calendar." buttonString:@"Save Event" bodyTextSize:14.0f buttonTextLines:2]; 

            }
        }
        else {

            [self displayStickieUniversalViewControllerTitleString:@"Device not configured to send SMS." bodyString:@"The event will be saved in the calendar." buttonString:@"Save Event" bodyTextSize:14.0f buttonTextLines:2]; 
        }
    }
}   
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Try checking to see what your result really is... `default` is just a catch-all case which is executed if the switch argument doesn't match any of the cases. – Sam Dufel Oct 22 '11 at 15:26
  • 1
    Have you tested if you can actually send SMS messages? Doc: Before presenting a message composition view, call the canSendText class method to ensure that the user’s device is appropriately configured. Do not attempt to present a message composition view if the canSendText method returns NO. If SMS delivery isn’t available, you can notify the user or simply disable the SMS features in your application. – jbat100 Oct 22 '11 at 15:44
  • I already have something in the app to catch it not being able to send the SMS. How do I print out what the real result is. – Brandon Frank Oct 22 '11 at 22:35
  • I think my problem was I didn't have {} brackets around my default, but now it always says sent. Does this work with iMessage??? – Brandon Frank Oct 22 '11 at 22:43
  • My version works with iMessage without any changes. – simongking Oct 23 '11 at 08:51
  • Now I am always getting it as sent, even if I go into text messaging and it will say failed. – Brandon Frank Oct 23 '11 at 13:57
  • Could you post your revised code so that I can look at that? – simongking Oct 28 '11 at 08:59

1 Answers1

0

It looks like you are using the wrong enum maybe something to do with it mine looks like this:

switch (result)
{
    case MessageComposeResultCancelled:
        break;
    case MessageComposeResultSent:
        break;
    case MessageComposeResultFailed:
        break;
    default:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"SMS" message:@"Sending Failed - Unknown Error :-("
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        [alert release];
    }

        break;
}
simongking
  • 740
  • 5
  • 15