0

I have a UITableViewController presenting a list of contacts, when the user selects a row, it'll show a UIActionSheet to ask the user an action (call, send sms...).

The user selects an action, and that first UIActionSheet will show another UIActionSheet which contains phone numbers.

The user selects a phone number, and this should show the SMS message composer.

The problem is that when the user selects a phone number, the message composer view doesn't show (just a black screen), and I receive the MessageComposeResultCancelled in the MFMessageComposeViewController's didFinishWithResult.

Which generates this warning "Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!"

How can I correctly call and show the SMS message composer?

(this works perfectly if I call it directly when the user selects a row in the list with didSelectRowAtIndexPath)

Here's some code :

1- call to first UIActionSheet in didSelectRowAtIndexPath method :

UIActionSheet *popupQuery;
...
[popupQuery showInView:self.view];

2- call to second UIActionSheet in clickedButtonAtIndex method :

UIActionSheet *popupQuery2;
...
[popupQuery showInView:self.view];

3- from the same method, call to message composer :

[self sendSMS:@"" recipientList:[phoneNumbers objectAtIndex:buttonIndex]];

the method that shows message composer :

    (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    if([MFMessageComposeViewController canSendText])
    {
        controller.body = bodyOfMessage;
        controller.recipients = recipients;
        controller.messageComposeDelegate = self;

        [self presentModalViewController:controller animated:YES];
    }
}
dzk
  • 91
  • 2
  • 8
  • Can you post some of the code on how you are showing/dismissing your view controllers ? As you can see from the error message, there is a problem with the way they are presented/dismissed. – Petar Mar 13 '13 at 11:26
  • Does this occur on an actual iDevice, or has it just been tested on the Simulator? `canSendText` Returns a Boolean value indicating whether the current device is capable of sending text messages. However, `canSendText` may return true on the Simulator as you may have the messages app installed on your Mac (_see additional question http://mby.me/Gw_) – Dan Clarke Mar 13 '13 at 12:53
  • I'm testing on an iphone 5 – dzk Mar 13 '13 at 13:32

2 Answers2

1

solution found here : MFMessageComposeViewController shows blank/white screen

    controller.recipients = [NSArray arrayWithObject:theRecipients];

theRecipients was an array containing only one element (the phone number selected)

Community
  • 1
  • 1
dzk
  • 91
  • 2
  • 8
0

As you don't want to try showing two modal controls in the same time, use actionSheet:didDismissWithButtonIndex: delegate method so that action sheet is hidden when you start to show messaging controller.

The following code shows composer which is not cancelled automatically. I can see 0 at log which is the value of MessageComposeResultCancelled, only when I press Cancel button. Are you trying to make a hack by pressing send button automatically ?

composer from action sheet delegate

MFMessageComposeViewController.h

enum MessageComposeResult {
    MessageComposeResultCancelled, //0
    MessageComposeResultSent,      //1
    MessageComposeResultFailed     //2
};

MyViewController.m

-(IBAction)onButtonPressed:(id)sender {
    UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"Title"
                                                        delegate:self
                                               cancelButtonTitle:@"Go out"
                                          destructiveButtonTitle:@"Show message composer"
                                               otherButtonTitles:nil, nil];
    [sheet showInView:self.view];
}

-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    if([MFMessageComposeViewController canSendText])
    {
        controller.body = @"body";
//        controller.recipients = recipients;
        controller.messageComposeDelegate = self;

        [self presentModalViewController:controller animated:YES];
    }
}

-(void) messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    NSLog(@"%d", result);
    [controller dismissModalViewControllerAnimated:YES];
}
A-Live
  • 8,904
  • 2
  • 39
  • 74
  • the thing is that the app receives "MessageComposeResultCancelled" just after calling the message composer – dzk Mar 13 '13 at 13:52
  • @dzk Does it happen when you show composer from `actionSheet:didDismissWithButtonIndex:` ? – A-Live Mar 13 '13 at 14:25
  • yes, instead of showing the message composer,it shows a blank screen like this http://img594.imageshack.us/img594/7624/screenshot20130302at931.png – dzk Mar 13 '13 at 14:44
  • @dzk updated the answer with proof of concept. Please share your delegate method. – A-Live Mar 13 '13 at 15:20
  • I'm using similar code than A-Live's. No I'm not trying to simulate the send action. Just showing the message composer. Sometimes in logs I have this message too : - init Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "The operation couldn’t be completed. (_UIViewServiceInterfaceErrorDomain error 3.)" - Remote compose controller timed out (NO)! – dzk Mar 13 '13 at 15:49
  • I'm doing it from a UITableViewController. If in the same file, I move the code to the table view didSelectRowAtIndexPath, it works perfectly – dzk Mar 13 '13 at 17:02
  • solution found here : http://stackoverflow.com/questions/15138497/mfmessagecomposeviewcontroller-shows-blank-white-screen – dzk Mar 18 '13 at 15:40
  • @dzk Interesting, you might want to file a bug. – A-Live Mar 18 '13 at 16:15