iOS Open Youtube App with Query (Url Schemes)

iOS open YouTube App with query (url schemes)

You can't use this http://www.youtube.com/results?search_query=foo for opening youtube app. If you use the above url it'll open the safari instead of youtube app.

There are only three URLSchemes available for opening youtube app:

  • http://www.youtube.com/watch?v=VIDEO_IDENTIFIER
  • http://www.youtube.com/v/VIDEO_IDENTIFIER
  • youtube://

Reference: iPhoneURLScheme

How to Open YouTube app with YouTube id on a button click in iOS

This way you first check if the YouTube app is installed on a device, and then open the app or else go to Safari.

    let youtubeId = "SxTYjptEzZs"    
var youtubeUrl = NSURL(string:"youtube://\(youtubeId)")!
if UIApplication.sharedApplication().canOpenURL(youtubeUrl){
UIApplication.sharedApplication().openURL(youtubeUrl)
} else{
youtubeUrl = NSURL(string:"https://www.youtube.com/watch?v=\(youtubeId)")!
UIApplication.sharedApplication().openURL(youtubeUrl)
}


Related Topics



Leave a reply



Submit