iOS 调用短信接口发送指定内容的消息

- (void)showSMSPicker {
    Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
    if (messageClass != nil) {
        if ([messageClass canSendText]) {
            [self displaySMSComposerSheet];
        }
        else {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"设备没有短信功能" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"iOS版本过低,iOS4.0以上才支持程序内发送短信" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

- (void)displaySMSComposerSheet {
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
    picker.messageComposeDelegate = self;

    if (orderInfo.strSerialNumber != nil) {
        NSString *msg = [NSString stringWithFormat:@"%@您好!您的预约号码:%@的订单已成功审批\n请在%@日期前至%@办理\n营业厅地址:%@\n推荐人电话:%@\n订单时间:%@",
                         orderInfo.strNewUser,orderInfo.strSerialNumber,orderInfo.strEndTime,orderInfo.strHall,orderInfo.strHallAddress,
                         orderInfo.strRecommenderNum,orderInfo.strRecommenderTime];    
        picker.body = [[NSString alloc] initWithString:msg];
    }
    else {
        NSString *msg = [NSString stringWithFormat:@"%@您好!您的预约订单已成功审批\n请在%@日期前至附近营业厅办理\n推荐人电话:%@\n订单时间:%@",
                         orderInfo.strNewUser,orderInfo.strEndTime,orderInfo.strRecommenderNum,orderInfo.strRecommenderTime];    
        
        picker.body = [[NSString alloc] initWithString:msg];
    }
    NSArray *array = [NSArray arrayWithObjects:orderInfo.strNewUserNum,nil];
    picker.recipients = array;
    [self presentModalViewController:picker animated:YES];
    [picker release];
    
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    switch (result)
    {
        case MessageComposeResultCancelled:
            //LOG_EXPR(@"Result: SMS sending canceled");
            break;
        case MessageComposeResultSent:
            {
                if (self.orderHistory == nil) {
                    self.orderHistory = [[OrderHistory alloc] init];
                    self.orderHistory.strRecommenderTime = self.orderInfo.strRecommenderTime;
                    self.orderHistory.strRecommenderNum = self.orderInfo.strRecommenderNum;
                }
                self.orderHistory.strOrderState = self.orderInfo.strOrderState;
                self.orderHistory.strAction = @"短信通知";
                NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
                [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
                [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
                [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSString *dateTime = [dateFormatter stringFromDate:[NSDate date]];
                self.orderHistory.strActionTime = [[NSString alloc] initWithString:dateTime];
                [self saveHistory];
                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"发送成功" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil];
                [alert show];
                [alert release];
            }
            break;
        case MessageComposeResultFailed:
            {

                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"发送失败" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil];
                [alert show];
                [alert release];
                
            }
            break;
        default:
            //LOG_EXPR(@"Result: SMS not sent");
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值