개발/Swift
SwiftUI Youtube 앱 설치여부에 따라 브라우저 혹은 앱 오픈
Sengwoolee
2021. 10. 6. 15:14
let youtubeId = "8cpOHY6bGYo" // 유튜브 비디오 ID
var youtubeUrl = NSURL(string:"youtube://\(youtubeId)")! // 유튜브 URL
if UIApplication.shared.canOpenURL(youtubeUrl as URL){ // 유튜브 앱 설치여부 체크
UIApplication.shared.open(youtubeUrl as URL)
} else { // 유튜브 앱 미설치시 브라우저 오픈
youtubeUrl = NSURL(string:"https://www.youtube.com/watch?v=\(youtubeId)")!
UIApplication.shared.open(youtubeUrl as URL)
}
반응형