-1

I would like to have capability to share content on multiple apps. I am using URL Scheme for that. But if the app is not installed, I would like to launch the web version of the relevant app.

Something like this:

func share(urlScheme: String)
{
     if (UIApplication.sharedApplication().canOpenURL(NSURL(string:urlScheme)!))
     {
         UIApplication.sharedApplication().openURL(NSURL(string: string:urlScheme)!)
     }
     else
     {
         // open web version somehow
     }
}
WangYudong
  • 4,335
  • 4
  • 32
  • 54
Luda
  • 7,282
  • 12
  • 79
  • 139

1 Answers1

3

here I add some sample for Uber customize your self , the reason we don't know what your urlScheme contains

for example

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]]];
    }
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143