/appA.swift Secret
Last active
June 3, 2019 19:48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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