1b0*_*b0t 14 youtube search ios
是否有使用指定搜索查询打开YouTube iOS应用的网址方案?
我试过了:
NSString *stringURL = @"http://www.youtube.com/results?search_query=foo";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Run Code Online (Sandbox Code Playgroud)
但这将打开Safari而不是YouTube应用程序.
Mid*_* MP 20
你无法使用它http://www.youtube.com/results?search_query=foo来打开youtube应用程序.如果你使用上面的网址,它将打开Safari而不是youtube应用程序.
打开youtube应用只有三个URLSchemes:
http://www.youtube.com/watch?v=VIDEO_IDENTIFIERhttp://www.youtube.com/v/VIDEO_IDENTIFIERyoutube://Vai*_*ran 15
这在iOS 9中运行良好
youtube://www.youtube.com/channel/<channel-id>
Swift 3和iOS 10+的更新
好的,有两个简单的步骤来实现这一目标:
首先,你必须修改Info.plist列出Youtube用LSApplicationQueriesSchemes.只需打开Info.plist源代码,然后粘贴:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>youtube</string>
</array>
Run Code Online (Sandbox Code Playgroud)
之后,您只需替换https://为,即可在Youtube应用程序中打开任何youtube URL youtube://.这是一个完整的代码,您可以将此代码链接到您拥有的任何按钮作为操作:
@IBAction func YoutubeAction() {
let YoutubeQuery = "Your Query"
let escapedYoutubeQuery = YoutubeQuery.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
let appURL = NSURL(string: "youtube://www.youtube.com/results?search_query=\(escapedYoutubeQuery!)")!
let webURL = NSURL(string: "https://www.youtube.com/results?search_query=\(escapedYoutubeQuery!)")!
let application = UIApplication.shared
if application.canOpenURL(appURL as URL) {
application.open(appURL as URL)
} else {
// if Youtube app is not installed, open URL inside Safari
application.open(webURL as URL)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30369 次 |
| 最近记录: |