Skip to content

Instantly share code, notes, and snippets.

@shishirthedev
Created May 7, 2019 08:28
Show Gist options
  • Save shishirthedev/10f34b871a798f771416ce82df9f181a to your computer and use it in GitHub Desktop.
Save shishirthedev/10f34b871a798f771416ce82df9f181a to your computer and use it in GitHub Desktop.
import UIKit
import SafariServices
class AppUtils: NSObject {
private override init() {}
public static let shared: AppUtils = AppUtils()
func showSafariVc(in vc: UIViewController, for url: String){
guard let url = URL(string: url) else { return }
let safariVc = SFSafariViewController(url: url)
vc.present(safariVc, animated: true, completion: nil)
}
func reviewAppOnAppStore(appleID: String?){
guard let appId = appleID else { return }
let appStoreLink = "https://itunes.apple.com/app/id\(appId)?action=write-review"
if let url = URL(string: appStoreLink) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
// Earlier versions
if UIApplication.shared.canOpenURL(url as URL) {
UIApplication.shared.openURL(url as URL)
}
}
}
}
func openAppOnAppStore(appleId: String){
let appStoreLink: String = "itms-apps://itunes.apple.com/app/id\(appleId)"
if let url = URL(string: appStoreLink) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
// Earlier versions
if UIApplication.shared.canOpenURL(url as URL) {
UIApplication.shared.openURL(url as URL)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment