IOS怎樣使用MessageUI Framework 發(fā)送短信息。使用MessageUI Framework 中的 MFMessageComposeViewController 發(fā)送短信息,另外其中的MFMailComposeViewController用于發(fā)送郵件。使用非常簡單:

目前創(chuàng)新互聯(lián)公司已為上1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、網(wǎng)站運營、企業(yè)網(wǎng)站設(shè)計、曲水網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
導(dǎo)入框架:MessageUI.framework
2. 添加協(xié)議:MFMessageComposeViewControllerDelegate
3. #import MessageUI/MessageUI.h
1 //判斷當(dāng)前設(shè)備是否可以發(fā)送短信息
2 if([MFMessageComposeViewController canSendText])
3 {
4
5 MFMessageComposeViewController *mc = [[MFMessageComposeViewController alloc] init];
6 //設(shè)置委托
7 mc.messageComposeDelegate = self;
8 //短信內(nèi)容
9 mc.body = @"nihao";
10 //短信接收者,可設(shè)置多個
11 mc.recipients = [NSArray arrayWithObject:@"10086",nil];
12
13 [self presentModalViewController:mc animated:YES];
14 [mc release];
15 }
16 else
17 {
18 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error",
19 message:@"The current device can not send SMS"
20 delegate:nil
21 cancelButtonTitle:"OK",
22 otherButtonTitles:nil];
23 [alert show];
24 [alert release];
25 }
26
27
28 #pragma mark -
29 #pragma mark MFMessageComposeViewControllerDelegate
30 -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
31 {
32 switch(result)
33 {
34 case MessageComposeResultCancelled:
35 ...
36 case MessageComposeResultFailed:
37 ...
38 case MessageComposeResultSend:
39 ...
40 default:
41 ...
42 }
43 }
這個方法,并不是很高級,因為只能寫好聯(lián)系人,下面提供一個方法,可以直接編輯好內(nèi)容還有收信人的!
不過本人求一個方法,可以直接把短信給發(fā)送出去了的,為這個方法只能編輯好,最后還是要用戶自己點擊一下發(fā)送按鈕,有不有什么方法可以直接發(fā)送出去了呢!希望各位賜教留言!!
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
程序內(nèi)調(diào)用系統(tǒng)發(fā)短信
pre
實現(xiàn)代理方法MFMessageComposeViewControllerDelegate
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:nil];
switch (result) {
case MessageComposeResultSent:
//信息傳送成功
}
/pre
發(fā)送短信
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:@該設(shè)備不支持短信功能
delegate:nil
cancelButtonTitle:@確定
otherButtonTitles:nil, nil];
[alert show];
}
}
參數(shù)phones:發(fā)短信的手機號碼的數(shù)組,數(shù)組中是一個即單發(fā),多個即群發(fā)。
/pre
調(diào)用發(fā)短信的方法
pre
[self showMessageView:[NSArray arrayWithObjects:@13888888888,@13999999999, nil] title:@test body:@你是土豪么,么么噠];
/pre
分享標題:ios開發(fā)發(fā)送短信,ios開發(fā) 讀取短信
網(wǎng)站地址:http://chinadenli.net/article21/dsieccd.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、建站公司、外貿(mào)網(wǎng)站建設(shè)、商城網(wǎng)站、網(wǎng)站設(shè)計公司、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)