【问题标题】:Launch web application when app is not installed未安装应用程序时启动 Web 应用程序
【发布时间】:2015-09-14 08:01:03
【问题描述】:

我希望能够在多个应用程序上共享内容。我正在为此使用 URL Scheme。但是如果没有安装应用程序,我想启动相关应用程序的网络版本。

类似这样的:

func share(urlScheme: String)
{
     if (UIApplication.sharedApplication().canOpenURL(NSURL(string:urlScheme)!))
     {
         UIApplication.sharedApplication().openURL(NSURL(string: string:urlScheme)!)
     }
     else
     {
         // open web version somehow
     }
}

【问题讨论】:

  • 您的意思是用户将直接进入 iTunes 中的应用安装页面,他们可以从那里下载该应用?
  • 不,到 Safari 中的 Web 应用程序

标签: ios objective-c swift url-scheme


【解决方案1】:

在这里我为Uber 自定义你的自我添加了一些示例,原因我们不知道你的urlScheme 包含什么

例如

斯威夫特

func share(urlScheme: String)
{
 if   (UIApplication.sharedApplication().canOpenURL(NSURL(string:"uber://")!))
 {

  // if your app is available it open the app 
     UIApplication.sharedApplication().openURL(NSURL(string: string:"uber://?openapp")!)
 }
 else
 {
     open web version somehow
    // it redirect to safari, safari directly open the web page on uber application, it does not redirect to app store

     UIApplication.sharedApplication().openURL(NSURL(string: string:"http://m.uber.com/?opneapp")!)
 }
}

Objective-C

 NSString *getUberDetails=[NSString stringWithFormat:@"client_id=vbtCwkGyqvDupQhpCcgCMo4VE-gIRw42&action=setPickup&pickup[latitude]=%f&pickup[longitude]=%f&pickup[nickname]=OuttAPP&dropoff[latitude]=%f&dropoff[longitude]=%f&dropoff[nickname]=%@&product_id=%@",[latitude floatValue],[longitude floatValue],[droplatitude floatValue],[dropLongtitude floatValue],[dropAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[[huberTableArr objectAtIndex:indexPath.row]objectForKey:@"productID"]];


    if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"uber://"]])
    {


        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString  stringWithFormat:@"uber://?%@",getUberDetails]]];

    }
    else
    {
        [[UIApplication sharedApplication] openURL: [NSURL URLWithString:[NSString stringWithFormat:@"http://m.uber.com/?%@",getUberDetails]]];
    }
}

【讨论】:

  • 就像在这里添加你的 String
猜你喜欢
  • 2021-07-03
  • 1970-01-01
  • 1970-01-01
  • 2018-04-09
  • 2018-11-05
  • 2011-03-11
  • 1970-01-01
  • 2013-06-02
  • 1970-01-01
相关资源
最近更新 更多