ios:sms消息作曲家没有显示

时间:2013-03-13 11:15:31

标签: ios uitableview uiactionsheet mfmessagecomposeview

我有一个UITableViewController呈现联系人列表,当用户选择一行时,它会显示一个UIActionSheet来询问用户一个动作(调用,发送短信......)。

用户选择一个动作,第一个UIActionSheet将显示另一个包含电话号码的UIActionSheet。

用户选择一个电话号码,这应显示SMS消息编写器。

问题是,当用户选择电话号码时,消息编辑器视图不显示(只是黑屏),我在MFMessageComposeViewController的didFinishWithResult中收到MessageComposeResultCancelled。

生成此警告“警告:正在进行演示或解雇时尝试从视图控制器中解除!”

如何正确调用和显示SMS消息编写器?

(如果我在用户使用didSelectRowAtIndexPath选择列中的行时直接调用它,则此方法非常有效)

以下是一些代码:

1-在didSelectRowAtIndexPath方法中调用第一个UIActionSheet:

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

在clickedButtonAtIndex方法中调用第二个UIActionSheet:

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

3-从同一方法,调用消息编写器:

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

显示消息编写器的方法:

    (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];
    }
}

2 个答案:

答案 0 :(得分:1)

此处找到解决方案:MFMessageComposeViewController shows blank/white screen

    controller.recipients = [NSArray arrayWithObject:theRecipients];

theRecipients是一个只包含一个元素(选择了电话号码)的数组

答案 1 :(得分:0)

由于您不想尝试同时显示两个模态控件,请使用actionSheet:didDismissWithButtonIndex:委托方法,以便在开始显示消息传递控制器时隐藏操作表。

以下代码显示未自动取消的composer。 只有当我按下0按钮时,我才会在日志中看到MessageComposeResultCancelled,这是Cancel的值。您是否尝试自动按send按钮进行黑客攻击?

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];
}