1.發簡訊 頭文件 頭部代理 發送信息 代理方法實現 2.撥打電話 3.發送郵件 4.發送QQ消息 ...
1.發簡訊
頭文件
#import <MessageUI/MessageUI.h>
頭部代理
@interface ViewController ()<MFMessageComposeViewControllerDelegate>
發送信息
- (void)senderMessage{ if([MFMessageComposeViewController canSendText]) { ///簡訊實例化 MFMessageComposeViewController * messageVc = [[MFMessageComposeViewController alloc] init]; ///目標號碼,可以多個 messageVc.recipients = @[@"18888888888",@"15555555555"]; messageVc.navigationBar.tintColor = [UIColor redColor]; messageVc.body = @"發送的內容-發送的內容-發送的內容"; messageVc.messageComposeDelegate = self; [self presentViewController:messageVc animated:YES completion:nil]; [[[[messageVc viewControllers] lastObject] navigationItem] setTitle:@"title"]; } else { NSLog(@"當前設備不支持簡訊功能"); } }
代理方法實現
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { ///dismiss MFMessageComposeViewController [controller dismissViewControllerAnimated:YES completion:nil]; if (result == MessageComposeResultSent) { NSLog(@"信息發送成功!"); } else if (result == MessageComposeResultFailed){ NSLog(@"信息發送失敗!"); } else if (result == MessageComposeResultCancelled){ NSLog(@"點擊了取消"); } else{ } }
2.撥打電話
- (void)dialPhone{ ///該方法直接撥打,不會彈出呼叫(取消) [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://18888888888"]]; ///該方法會彈出是否取消呼叫 UIWebView*callWebview =[[UIWebView alloc] init]; NSURL *telURL =[NSURL URLWithString:@"tel:18888888888"]; [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]]; [self.view addSubview:callWebview]; }
3.發送郵件
- (void)senderEmail{ NSString *urlStr =@"mailto:[email protected]?subject=郵件主題(此參數可不傳)&body=郵件內容(此參數可不傳)"; NSURL *url = [NSURL URLWithString:urlStr] ; [[UIApplication sharedApplication] openURL:url]; }
4.發送QQ消息
- (void)senderQQ{ ///111111111111為QQ號碼 NSString *url = @"mqq://im/chat?chat_type=wpa&uin=111111111111&version=1&src_type=web"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; }