未安装应用程序时启动 Web 应用程序
Launch web application when app is not installed
我希望能够在多个应用程序上共享内容。为此,我正在使用 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
}
}
我在这里添加了一些示例,用于 Uber
自定义您的自我,因为我们不知道您的 urlScheme
包含什么
例如
Swift
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]]];
}
}
我希望能够在多个应用程序上共享内容。为此,我正在使用 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
}
}
我在这里添加了一些示例,用于 Uber
自定义您的自我,因为我们不知道您的 urlScheme
包含什么
例如
Swift
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]]];
}
}