如何向 MFMessageComposeViewController 添加监听器?

发布于 2024-09-12 21:17:22 字数 243 浏览 3 评论 0原文

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

例如,我知道对于文本字段,侦听器的示例如下: [textField addTarget:self 操作:@selector(methodName) forControlEvents:UIControlEventEditingDidEndOnExit];

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 listener would be:
[textField addTarget:self action:@selector(methodName) forControlEvents:UIControlEventEditingDidEndOnExit];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我还不会笑 2024-09-19 21:17:22

Google 非常有帮助...

第三个结果是短信教程

相关代码:

- (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 案例以了解消息何时发送。

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.

天生の放荡 2024-09-19 21:17:22

您想要向 MFMessageComposeViewController 添加委托。在委托的 messageComposeViewController:didFinishWithResult: 方法中,您可以检查 result 参数以了解用户是否取消或发送了短信。

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文