Skip to content

Instantly share code, notes, and snippets.

@eldare
Last active June 3, 2019 19:48
func startAppB(withUsername: String) {
// init the instance to access our shared storage
let group = UserDefaults(suiteName: "group.myAmazingApp")
// store username in shared storage
group?.set("eldar", forKey: "username")
// prepare App B's URL Scheme
let targetAppUrl = URL(string: "appB://")
// is App B availalbe on device?
if UIApplication.shared.canOpenURL(targetAppUrl) {
// App B in installed, open it
openUrl(targetAppUrl)
} else {
// App B is not installed, go to app store
let appStoreUrl = URL(string: "https://itunes.apple.com/app/id123456")
openUrl(appStoreUrl)
}
}
func openUrl(_ url: URL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment