-7

I found an answer to implement a link to get rated on the app store (App store link for "rate/review this app"). Answer is:

let appID = "Your App ID on App Store"
let urlStr = "itms-apps://itunes.apple.com/app/id\(appID)" // 
(Option 1) Open App Page    
let urlStr = "itms-apps://itunes.apple.com/app/viewContentsUserReviews?
id=\(appID)" // (Option 2) Open App Review Tab


if let url = URL(string: urlStr), UIApplication.shared.canOpenURL(url) 
{
if #available(iOS 10.0, *) {
    UIApplication.shared.open(url, options: [:], completionHandler: 
nil)
} else {
    UIApplication.shared.openURL(url)
}
}

I am having trouble understanding how to implement this. Particularly I don't understand how the if statement will take the user to the app store.

Thanks.

Arjuna Deva
  • 275
  • 4
  • 17

2 Answers2

1

The first part

let appID = "Your App ID on App Store"
let urlStr = "itms-apps://itunes.apple.com/app/id\(appID)" // 
(Option 1) Open App Page    
let urlStr = "itms-apps://itunes.apple.com/app/viewContentsUserReviews?
id=\(appID)" // (Option 2) Open App Review Tab

gets the url of your app in itunes review section so user can write a review

The second part

if let url = URL(string: urlStr), UIApplication.shared.canOpenURL(url) 

checks if the url is valid and can be opened by application.shared if ok it's check the needed function according to the current version. Actually system know that the app needs to open the url , when it executes the statement , look at open

  UIApplication.shared.open(url, options: [:], completionHandler:nil)

Or

  UIApplication.shared.openURL(url)
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

you are opening url with itms-apps:// scheme. So system itself knows what app should handle this.

mkowal87
  • 596
  • 4
  • 19