macOS, iOS

[iOS] 인스타그램에서 열기

SweetDev 2021. 6. 1. 12:56
                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)
                  }
                }