ios撥打電話 發(fā)送短信(調(diào)用系統(tǒng))

撥打電話

1,這種方法,撥打完電話回不到原來的應(yīng)用,會停留在通訊錄里,而且是直接撥打,不彈出提示。

NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"186xxxx6979"];    
// NSLog(@"str======%@",str);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

2,這種方法,打完電話后還會回到原來的程序,也會彈出提示,推薦這種。

NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"186xxxx6979"];   
UIWebView * callWebview = [[UIWebView alloc] init]; 
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];  
[self.view addSubview:callWebview];
[callWebview release];    
[str release];

3,這種方法也會回去到原來的程序里(注意這里的telprompt),也會彈出提示。

NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"186xxxx6979"];    
//NSLog(@"str======%@",str);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

發(fā)送短信

  • 程序外調(diào)用系統(tǒng)發(fā)短信
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://13888888888"]];
  • 程序內(nèi)調(diào)用系統(tǒng)發(fā)短信

1)導(dǎo)入MessageUI.framework,并引入頭文件:

#import <MessageUI/MessageUI.h>

2)實現(xiàn)代理方法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;
    }
}

3)發(fā)送短信

    -(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];//修改短信界面標(biāo)題
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
                                                        message:@"該設(shè)備不支持短信功能"
                                                       delegate:nil
                                              cancelButtonTitle:@"確定"
                                              otherButtonTitles:nil, nil];
        [alert show];
    }
}

參數(shù)phones:發(fā)短信的手機號碼的數(shù)組,數(shù)組中是一個即單發(fā),多個即群發(fā)。

4)調(diào)用發(fā)短信的方法

  [self showMessageView:[NSArray arrayWithObjects:@"13888888888",@"13999999999", nil] title:@"test" body:@"你是土豪么,么么噠"];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容