iOS 发短信

本文详细介绍了如何在应用中集成短信功能,并通过代理回调机制处理短信发送过程中的各种状态变化,包括发送取消、发送失败及发送成功的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

    UINavigationController *nav = appDelegate.navigationController;

    

    if( [MFMessageComposeViewController canSendText] ){

        

        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init];

        

        controller.recipients = [NSArray arrayWithObject:tele];

        controller.body = @"您好,我在海报找工作看到您的招聘信息,很感兴趣,想和您详细了解一下。";

        controller.messageComposeDelegate = self;

        

        [nav presentViewController:controller animated:YES completion:^{

            

            [MBProgressHUD hideHUDForView:self.view animated:YES];

            

        }];

        //[[[[controller viewControllers] lastObject] navigationItem] setTitle:@"测试短信"];//修改短信界面标题

    }else{

        

        [MBProgressHUD hideHUDForView:self.view animated:YES];

        UIWindow *window = [UIApplication sharedApplication].keyWindow;

        [window makeToast:@"设备没有短信功能" duration:1 position:@"center"];

    }



#pragma mark - 短信代理回调 MFMessageComposeViewControllerDelegate

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{

    

    UIWindow *window = [UIApplication sharedApplication].keyWindow;

    //关键的一句   不能为YES

    [controller dismissViewControllerAnimated:NO completion:^{

        

        switch ( result ) {

                

            case MessageComposeResultCancelled:

                [window makeToast:@"发送取消" duration:1 position:@"center"];

                break;

            case MessageComposeResultFailed:// send failed

                [window makeToast:@"发送失败" duration:1 position:@"center"];

                break;

            case MessageComposeResultSent:

                [window makeToast:@"发送成功" duration:1 position:@"center"];

                break;

            default:

                break;

        }

    }];

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值