开发者

How to add a listener to an MFMessageComposeViewController?

I am trying to send an SMS on an iPhone using MFMessageComposeVieController and I want to add a listener that recognizes when the SMS is sent (in other words, when the user presses "Send"). What is the syntax for this?

For example, I know that with a textField, an example of a list开发者_如何学Pythonener would be: [textField addTarget:self action:@selector(methodName) forControlEvents:UIControlEventEditingDidEndOnExit];


Google is very helpful...

Third result is an SMS tutorial.

Relevant code:

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

Implement the MessageComposeResultSent case to know when the message has been sent.


You want to add a delegate to your MFMessageComposeViewController. In the delegate's messageComposeViewController:didFinishWithResult: method, you can check the result parameter to see whether the user canceled or sent the SMS.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜