zoukankan      html  css  js  c++  java
  • 随记(二)--是否能打开手机某个应用

     1 NSLog(@"%d",[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]);
     2  
     3         if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap:"]]){
     4             NSString *urlString = [NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:%@&mode=transit",
     5                                    _startCoor.latitude, _startCoor.longitude, _endCoor.latitude, _endCoor.longitude, _title.text];
     6             
     7             urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
     8             NSURL *url = [NSURL URLWithString:urlString];
     9 
    10             [[UIApplication sharedApplication] openURL:url];
    11         } else {
    12             UIAlertController *appContro = [UIAlertController alertControllerWithTitle:@"提示" message:@"您是否立即前往APPStore安装!" preferredStyle:UIAlertControllerStyleAlert];
    13             UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"稍后安装" style:UIAlertActionStyleDefault handler:nil];
    14             UIAlertAction *download = [UIAlertAction actionWithTitle:@"立即安装" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    15                 NSString *appStr = [NSString stringWithFormat:@"https://appsto.re/cn/ce98A.i"];
    16                 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStr]];
    17             }];
    18             [appContro addAction:download];
    19             [appContro addAction:cancel];
    20             
    21             [self presentViewController:appContro animated:YES completion:nil];
    22         }
    23     }];

     NSLog(@"%d",[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]); 

    开始这行不管手机上是否安装le百度地图应用,返回结果都会是NO;因项目中对该链接是不信任的,从而导致canOpenURL返回都是NO;

    打开info.plist 添加LSApplicationQueriesSchemes

  • 相关阅读:
    Mongoose使用
    Koa原理和封装
    微信用户授权
    Koa微信公众号开发
    Koa2+mongoose
    NodeJS-API
    jquery下json数组的操作用法实例
    SqlCacheDependency:asp.net SQL缓存依赖
    SqlCacheDependency轮询数据库表的更改情况的频率
    设置浏览器地址栏URL前面显示的图标
  • 原文地址:https://www.cnblogs.com/1394389856fei/p/5275041.html
Copyright © 2011-2022 走看看