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
Looping Through Nsattributedstring Attributes to Increase Font Size
Right Way of Determining Internet Speed in iOS 8
-Canopenurl: Failed for Url: "Fbauth2:/" (Osstatus Error -10814.)"
Libraries Not Found When Using Cocoapods with iOS Logic Tests
What Is Prefix.Pch File in Xcode
How to Get Uiscrollview Vertical Direction in Swift
Programmatically Switching Between Tabs Within Swift
Rotation Behaving Differently on iOS6
How to Create a Hex Color String Uicolor Initializer in Swift
Open Uitableview Edit Action Buttons Programmatically
How to Call Presentviewcontroller from Within a Uicollectionviewcell
How to Lookup a String Constant at Runtime in Objective-C
How to Use Apple's New .P8 Certificate for Apns in Firebase Console
Find the Tangent of a Point on a Cubic Bezier Curve
Crashlytics in iOS Won't Proceed Past "Build Your Project" in Fabric App