iOS學習筆記(十四)——打電話、發簡訊

來源:互聯網
上載者:User

 

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10010"]];//打電話

 

 

 

 

    UIWebView*callWebview =[[UIWebView alloc] init];    NSURL *telURL =[NSURL URLWithString:@"tel:10010"];    [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];    //記得添加到view上    [self.view addSubview:callWebview];



 

 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://10010"]];

 

2、發簡訊

 

 [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10010"]];//發簡訊

 

 

iOS4.0新加入了MFMessageComposeViewCont

 

 


body :簡訊內容

 

添加協議:

 

#import <MessageUI/MessageUI.h>@interface DemoViewController : UIViewController <MFMessageComposeViewControllerDelegate>@end


 

 

- (void)showMessageView{        if( [MFMessageComposeViewController canSendText] ){                MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init]; //autorelease];                controller.recipients = [NSArray arrayWithObject:@"10010"];             controller.body = @"測試發簡訊";                controller.messageComposeDelegate = self;        [self presentModalViewController:controller animated:YES];                [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"測試簡訊"];//修改簡訊介面標題    }else{                [self alertWithTitle:@"提示資訊" msg:@"裝置沒有簡訊功能"];            }    }//MFMessageComposeViewControllerDelegate- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{        [controller dismissModalViewControllerAnimated:NO];//關鍵的一句   不能為YES        switch ( result ) {                    case MessageComposeResultCancelled:            [self alertWithTitle:@"提示資訊" msg:@"發送取消"];             break;        case MessageComposeResultFailed:// send failed            [self alertWithTitle:@"提示資訊" msg:@"發送成功"];             break;        case MessageComposeResultSent:            [self alertWithTitle:@"提示資訊" msg:@"發送失敗"];             break;        default:            break;     }}- (void) alertWithTitle:(NSString *)title msg:(NSString *)msg {        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title           message:msg           delegate:self           cancelButtonTitle:nil           otherButtonTitles:@"確定", nil];                            [alert show];                 }          



 

 

 


@張興業TBOW

 

 

參考:

http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMessageComposeViewController_class/Reference/Reference.html

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.