1.打电话
// iOS10以后调用会有延迟 处理如下
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
if (carrier.isoCountryCode) {
NSString *urlStr = [NSString stringWithFormat:@"tel:%@",self.staffModel.phone];
if ([UIDevice currentDevice].systemVersion.floatValue > 10.0) {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr] options:@{} completionHandler:^(BOOL success) {
sender.enabled = YES;
}];
});
}else {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
sender.enabled = YES;
});
}
} else {
[MBProgressHUD bwm_showTitle:@"该手机未安装SIM卡" toView:self.view hideAfter:MBHiddenTime];
sender.enabled = YES;
}
2.发短信
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
- (IBAction)clickSmsBtn:(id)sender {
if( [MFMessageComposeViewController canSendText] ){
MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init];;
controller.recipients = [NSArray arrayWithObject:self.myText.text];
controller.body = @"测试发短信";
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}else{
NSLog(@"设备不具备短信功能");
}
}
/*短信发送完成后返回app*/
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
[controller dismissViewControllerAnimated:YES completion:nil];
if (result == MessageComposeResultSent) {
NSLog(@"发送成功");
}
}
3.发邮件
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
- (IBAction)clickEmailBtn:(id)sender {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObjects:self.myText.text, nil]];
[controller setSubject:@"邮件测试"];
[controller setMessageBody:@"Hello " isHTML:NO];
[self presentViewController:controller animated:YES completion:nil];
}else{
NSLog(@"设备不具备发送邮件功能");
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
if (result == MFMailComposeResultSent) {
NSLog(@"邮件发送成功");
}
[self dismissViewControllerAnimated:YES completion:nil];
}
4.跳转到应用商店
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/zsdl/id796332505?mt=8"]];
网友评论