iOS-打電話、發簡訊、發郵件【指定QQ使用者發送QQ訊息】,ios-訊息
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:xxxxxxxx@xxxx.com?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]];}