美文网首页
调用系统功能

调用系统功能

作者: lym不解释 | 来源:发表于2017-01-10 13:58 被阅读14次

    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"]];
    

    相关文章

      网友评论

          本文标题:调用系统功能

          本文链接:https://www.haomeiwen.com/subject/bzdkbttx.html