guard let url = URL(string: UIApplication.openSettingsURLString) else { return }
if UIApplication.shard.canOpenURL(url) {
UIApplication.shard.open(url)
}
❖ 다른 앱으로 이동
- info.plist > Queried URL Schemes [ ] > url scheme 추가
let urlString = "..."
guard let appURL = URL(string: urlString) else { return }
if UIApplication.shared.canOpenURL(appURL) {
UIApplication.shared.open(appURL, options: [:], completionHandler: nil)
} else {
// 앱이 설치되어 있지 않은 경우 : appID값으로 앱스토어 연결
let appStoreURL = URL(string: "<https://apps.apple.com/app/\\(appID)>")
UIApplication.shared.open(appStoreURL, options: [:], completionHandler: nil)
}
❖ 전화 연결
static func callNumber(phoneNumber: String) {
if let phoneURL = URL(string: "tel://\\(phoneNumber)") {
if UIApplication.shared.canOpenURL(phoneURL) {
UIApplication.shared.open(phoneURL)
} else {
print("Fail to call")
}
}
}