打電話功能
//直接跳轉到打電話的界面
NSString *allString = [NSString stringWithFormat:@"tel:10010"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:allString]];
//撥号之前會彈框詢問使用者是否撥号
NSURL *url = [NSURL URLWithString:@"telprompt://10010"];
[[UIApplication sharedApplication] openURL:url];
發短信功能
//直接跳轉到發短信界面
NSURL *url = [NSURL URLWithString:@"sms://10010"];
[[UIApplication sharedApplication] openURL:url];
//編輯好手機号及内容後再跳轉
(1)導入MessageUI.framework
(2)#import <MessageUI/MessageUI.h>
(3)<MFMessageComposeViewControllerDelegate>
(4)
//顯示發短信的控制器
MFMessageComposeViewController *vc =[[MFMessageComposeViewController alloc] init];
// 設定短信内容
vc.body = @"吃飯了沒?";
//設定收件人清單
vc.recipients = @[@"10086", @"13838383838"];
//設定代理
vc.messageComposeDelegate = self;
// 顯示控制器
[self presentViewController:vc animated:YES completion:nil];
//代理方法,當短信界面關閉的時候調用,發完後會自動回到原應用
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
// 關閉短信界面
[controller dismissViewControllerAnimated:YES completion:nil];
if (result == MessageComposeResultCancelled) {
NSLog(@"取消發送");
}
else if (result == MessageComposeResultSent) {
NSLog(@"已經發出");
} else {
NSLog(@"發送失敗");
}
}