如何将侦听器添加到MFMessageComposeViewController?

时间:2010-08-05 17:26:19

标签: iphone events uitextfield

我正在尝试使用MFMessageComposeVieController在iPhone上发送短信,我想添加一个能够识别SMS发送时间的监听器(换句话说,当用户按下“发送”时)。这是什么语法?

例如,我知道使用te​​xtField,一个监听器的例子是: [textField addTarget:self action:@selector(methodName)forControlEvents:UIControlEventEditingDidEndOnExit];

2 个答案:

答案 0 :(得分:1)

Google is very helpful...

第三个结果是an SMS tutorial

相关代码:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
                 didFinishWithResult:(MessageComposeResult)result
{
    switch (result) {
        case MessageComposeResultCancelled:
            NSLog(@"Cancelled");
            break;
        case MessageComposeResultFailed:
            UIAlertView *alert = [[UIAlertView alloc] 
                          initWithTitle:@"MyApp" 
                                message:@"Unknown Error"
                               delegate:self 
                      cancelButtonTitle:@”OK” 
                      otherButtonTitles:nil];
            [alert show];
            [alert release];
            break;
        case MessageComposeResultSent:

            break;
        default:
            break;
    }

    [self dismissModalViewControllerAnimated:YES];
}

实施MessageComposeResultSent案例以了解邮件何时发送。

答案 1 :(得分:0)

您想要将代理人添加到MFMessageComposeViewController。在委托的messageComposeViewController:didFinishWithResult:方法中,您可以检查结果参数以查看用户是否取消或发送了短信。

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
                 didFinishWithResult:(MessageComposeResult)result {
        switch(result) {
        case MessageComposeResultCancelled:
            // user canceled sms
            break;
        case MessageComposeResultSent:
            // user sent sms
            break;
        case MessageComposeResultFailed:
            // sms send failed
            break;
        default:
            break;
}