let screenName = data?.instagram ?? "" // CHANGE THIS
let appURL = URL(string: "instagram://user?username=\(screenName)")!
let webURL = URL(string: "https://instagram.com/\(screenName)")!
if UIApplication.shared.canOpenURL(appURL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(appURL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(appURL)
}
} else {
// redirect to safari because the user doesn't have Instagram
if #available(iOS 10.0, *) {
UIApplication.shared.open(webURL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(webURL)
}
}