在您的App Swift代码上启动Youtube频道 [英] launch Youtube channel on your App Swift Code
问题描述
我花了几天的时间找到可以从我的应用程序打开的YouTube频道的Swift代码.但是我根本找不到,请有人帮我! 我需要Swift中的代码.
I have spent some days to find the Swift code for youtube Channel to open from my app. but i couldn't find At all, can some one help me please!! i need the Code in Swift.
推荐答案
Swift 3和iOS 10+的更新
Update for Swift 3 and iOS 10+
好的,这是在Swift 3中的操作方法.基本上,有两个简单的步骤可以实现这一点:
OK, here is how to do it in Swift 3. Basically, there are two easy steps to achieve this:
首先,您必须修改Info.plist
以将Youtube
与LSApplicationQueriesSchemes
一起列出.只需打开Info.plist
作为源代码,并将其粘贴:
First, you have to modify Info.plist
to list Youtube
with LSApplicationQueriesSchemes
. Simply open Info.plist
as a Source Code, and paste this:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>youtube</string>
</array>
此后,您只需将https://
替换为youtube://
,即可在Youtube应用程序中打开任何youtube URL.这是完整的代码,您可以将此代码链接为操作中具有的任何按钮:
After that, you can open any youtube URL inside Youtube application by simply substituting https://
with youtube://
. Here is a complete code, you can link this code to any button you have as an Action:
@IBAction func YoutubeAction() {
let YoutubeUser = "Your Username"
let appURL = NSURL(string: "youtube://www.youtube.com/user/\(YoutubeUser)")!
let webURL = NSURL(string: "https://www.youtube.com/user/\(YoutubeUser)")!
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)
}
}
这篇关于在您的App Swift代码上启动Youtube频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!