0

I want to link from my app directly to the app store.

I am using this code:

   var url  = NSURL(string: "itms-apps://itunes.com/apps/companyname/appname")
            if UIApplication.sharedApplication().canOpenURL(url!) == true  {
                UIApplication.sharedApplication().openURL(url!)
            }

When the name of the app has no space in it, it works fine. But is there is a space in the app name, It does not link to the app itself, but it links to the page with all my apps. How come?


Example: if app name = bobbie , I use:

var url  = NSURL(string: "itms-apps://itunes.com/apps/mycompany/bobbie")
            if UIApplication.sharedApplication().canOpenURL(url!) == true  {
                UIApplication.sharedApplication().openURL(url!)
            }

(works prefectly)

But it app name = bob bie , I use:

var url  = NSURL(string: "itms-apps://itunes.com/apps/mycompany/bob-bie")
            if UIApplication.sharedApplication().canOpenURL(url!) == true  {
                UIApplication.sharedApplication().openURL(url!)
            }

But this doesn't link to the app...

sangony
  • 11,636
  • 4
  • 39
  • 55
sdd
  • 889
  • 8
  • 29
  • possible duplicate of [Launching App Store from App in Swift](http://stackoverflow.com/questions/25940109/launching-app-store-from-app-in-swift) – sangony May 20 '15 at 13:18

2 Answers2

0

Use the link provided in iTunes connect for your app.

  1. Open iTunes Connect
  2. Log in
  3. Click "My apps"
  4. Select your app
  5. Click "More"
  6. Copy link for "Show in App Store"
Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62
0

You just need to replace the space by %20 using stringByAddingPercentEscapesUsingEncoding:

let link = "itms-apps://itunes.com/apps/mycompany/bob bie"
if let linkWithPercentEscape = link.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {
    println(linkWithPercentEscape)
    if let url  = NSURL(string: linkWithPercentEscape) {
        println(url)
        if UIApplication.sharedApplication().canOpenURL(url)  {
            UIApplication.sharedApplication().openURL(url)

        }
    }
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571