iOS 短信調用

<pre>[[UIApplication sharedApplication]openURL:[NSURL URLWithString:
@sms://13888888888]];
-(void)messageComposeViewController(MFMessageComposeViewController*)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:nil];
switch
(result) {
case
MessageComposeResultSent:
信息傳送成功
break;
case
MessageComposeResultFailed:
信息傳送失敗
break;
case
MessageComposeResultCancelled:
信息被用戶取消傳送
break;
default:

break;
}

}</pre>
程序內調用系統發短信
<pre>

import <messageui messageui.h=""></messageui>

實現代理方法MFMessageComposeViewControllerDelegate

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:nil];
switch (result) {
case MessageComposeResultSent:
//信息傳送成功

        break;
    case MessageComposeResultFailed:
        //信息傳送失敗


        break;
    case MessageComposeResultCancelled:
        //信息被用戶取消傳送


        break;
    default:
        break;
}

}
</pre>
發送短信
<pre>
-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body
{
if( [MFMessageComposeViewController canSendText] )
{
MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
controller.recipients = phones;
controller.navigationBar.tintColor = [UIColor redColor];
controller.body = body;
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
[[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面標題
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@提示信息
message:@該設備不支持短信功能
delegate:nil
cancelButtonTitle:@確定
otherButtonTitles:nil, nil];
[alert show];
}
}
參數phones:發短信的手機號碼的數組,數組中是一個即單發,多個即群發。
</pre>
調用發短信的方法
<pre>
[self showMessageView:[NSArray arrayWithObjects:@13888888888,@13999999999, nil] title:@test body:@你是土豪么,么么噠];
</pre>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容