美文网首页
调用系统应用

调用系统应用

作者: wpf_register | 来源:发表于2016-07-30 14:22 被阅读33次

    应用间跳转

    应用A 跳转至应用B,对B应用设置如示:

    • 首先需要注册 URL Schemes
    identifier 可选 URL Schemes 必填
    • 接受跳转时发过来的URL
    //下面方法专门处理从第三方跳转过来的
    //9.0以上使用的方法
    -(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
    
      //url 为跳转时的URL
       url.scheme  协议 a123://
       url.host  域名    abc
       url.absoluteString  完整的url字符串  a123://abc
    
        return YES;
    }
    //适配低版本
    -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation {
        return YES;
    }
    //2.0出现过,现在多不用
    -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
        return YES;
    }
    

    应用跳转事件

    //Button的点击效果
    - (IBAction)goAction:(UIButtion*)sender{
        //格式为   URL Schemes://(要传递的值)
        NSURL *url = [NSURL URLWithString:@"a123://abc"];
        [[UIApplication sharedApplication] openURL:url];
    }
    //微信
    - (IBAction)weixinAction:(UIButton *)sender {
        
       NSURL *url = [NSURL URLWithString:@"weixin://"];   
        [[UIApplication sharedApplication] openURL:url];
    }
    //新浪微博
    - (IBAction)weiboAction:(UIButton *)sender {
        
        NSURL *url = [NSURL URLWithString:@"weibo://"];
        [[UIApplication sharedApplication] openURL:url];
    }
    

    系统应用

    - (IBAction)systemAction:(UIButton *)sender {
        
       //调用自带mail
    
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzlzh.com"]];
    
       //调用电话phone
    不提示直接拨号并打出,且无法回到应用
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];
    
        //这种调用就会弹出提示框
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://8008808888"]];
    
    
       //调用SMS,这种不通指定短信内容,不能自动回到原应用
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://8008808888"]];
    
        //调用safari
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com"]];
    
    }
    //强制横屏
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    

    关于拨打电话

    -(void)onCall:(NSString*)phoneNumber
    {
       
        //判断是否是iPhone手机
        if ([UtilFun isIphoneAboutHardWare]) {
            //只实现拨打功能,防止遮挡frame设置为0
            UIWebView *callWebview =[[UIWebView alloc] initWithFrame:CGRectZero];
            NSURL *telURL =[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",number]];
            [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
            [self.view addSubview:callWebview];
        }else {
            NSString*str = [NSString stringWithFormat:@"您的设备没有打电话功能,电话号码:%@",phoneNumber];
        }
    }
    

    关于发短信

    1.导入框架并实现协议
    MessageUI.framework
    #import <MessageUI/MessageUI.h>
    @interface ViewController ()
     
    2.编辑短信内容,群发对象,设置代理并弹出短信界面
       //要做安全判断,否则提示用户不能发信息
      if( [MFMessageComposeViewController canSendText] )
    
         MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
         //编辑内容
          messageVC.body = @"你好,我是亲爱的大倩倩";
         //可以群发
          messageVC.recipients = @[@"000000",@"111111",@"222222"];
          messageVC.messageComposeDelegate = self;
         [self presentViewController:messageVC animated:YES completion:nil];
    }
     
    3.实现代理:短信发完后的回调,在此方法中设置返回原应用程序
    参数1: 短信控制器
    参数2:短信发送结果
    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
    {
        [controller dismissViewControllerAnimated:YES completion:nil];
     
        NSString *messageResult;
        if (result == MessageComposeResultCancelled)
            messageResult = @"短信取消发送";
        else if(result == MessageComposeResultSent)
            messageResult = @"短信已发送";
        else
            messageResult = @"短信发送失败!";
     
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:messageResult message:nil preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *myAction = [UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleCancel handler:nil];
        [alertController addAction:myAction];
        [self presentViewController:alertController animated:YES completion:nil];
     
    }
    
    

    相关文章

      网友评论

          本文标题:调用系统应用

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