CocoaPods 分发已废弃且 trunk 上仅到 0.9.0,新项目应改用 SwiftPM;使用 Data API 前需自行到 Google 控制台申请 API key 并调用 setAPIKey 设置;从 0.9.0 升级需 iOS 13,仍支持 iOS 11/12 的应用只能停留在旧版本
YoutubeKit
rinovMIT活跃维护封装 YouTube IFrame API 和 Data API 的 Swift 视频播放器库,帮 iOS 开发者快速搭建带播放和视频数据查询的 YouTube 应用。
YoutubeKit is a video player that fully supports Youtube IFrame API and YoutubeDataAPI for easily create a Youtube app
dependencies: [
.package(url: "https://github.com/rinov/YoutubeKit.git", from: "0.14.0")
]README 未说明;仅要求 iOS 13 及以上,无显存或 GPU 相关要求
iOS 库,封装 YouTube IFrame 播放器与 Data API v3,帮你快速搭建 YouTube 应用
封装 YouTube IFrame API 和 Data API 的 Swift 视频播放器库,帮 iOS 开发者快速搭建带播放和视频数据查询的 YouTube 应用。
核心能力
- 基于 WKWebView 封装 IFrame 播放器 YTSwiftyPlayer
- 用 VideoEmbedParameter 提供类型安全的播放器参数
- 覆盖 Data API v3 的 13 类 list 请求
- 支持 nextPageToken 分页拉取列表数据
- 提供 delegate 回调播放状态、错误与自动播放拦截
容易踩的坑
- 0.14.0YoutubeKit 0.14.0最新正式版2026-10-06 · 2026-10-06 00:13 UTC
YoutubeKit 0.14.0
This release updates compatibility with current Xcode and Swift toolchains, improves player diagnostics, and adds iOS client identity to Data API requests while preserving existing public APIs from 0.13.0.
Changes
- Support Swift 5 and Swift 6 language modes with synchronized networking state and credentials.
- Derive the embedded player's default Referer from the host app's bundle ID.
- Add optional raw error-code and blocked-autoplay callbacks, including support for reporting error 153.
- Support fractional-second seeking while retaining the existing
Intoverload and method references. - Fit the bundled player HTML to the device viewport in portrait and landscape.
- Automatically send
X-Ios-Bundle-Identifierfor API-key requests, preserving explicit header values and OAuth behavior. - Add regression coverage for networking, resources, player callbacks, seeking, and the Example scene lifecycle.
- Document retired YouTube features with English deprecation messages and migration guidance.
Compatibility and upgrading
- Minimum deployment target: iOS 13, unchanged from 0.13.0.
- SwiftPM tools version: 5.3; default library language mode: Swift 5.
- Existing delegates, enum cases, completion handlers, and
Decodableresponses remain supported. - Custom player base URLs continue to take precedence. Hosts without a valid bundle ID should provide an explicit identity URL.
- Deprecated APIs remain callable but cannot restore server features removed by YouTube. New warnings may affect builds that treat warnings as errors.
- CocoaPods distribution is deprecated and this version is not published to CocoaPods trunk (latest there: 0.9.0). Migrate to SwiftPM, or reference the
0.14.0tag with:gituntil migrating. - Upgrading from 0.9.0 requires iOS 13, compared with iOS 11 in that version. Apps supporting iOS 11 or 12 should retain a compatible older version.
- SwiftPM is recommended for new integrations. Carthage has no maintained shared framework target in this repository.
Known limitations
- Looping a time range may not preserve its start/end boundaries on subsequent iterations (#35).
- The reported playback error 4 remains under investigation (#111); this release does not claim to resolve it.
- The header change addresses missing iOS identity for restricted keys (#89). Other API configuration and quota errors can still return 403.
- Playback availability, autoplay, branding, and quality remain subject to YouTube and WebKit behavior.
See the README for installation and migration guidance.
- 0.13.02026-01-24 · 2026-01-24 17:25 UTC
查看更新说明
What's Changed
- Fix YouTube video playback errors by updating base URL to youtube-nocookie.com by @davidgalarza in https://github.com/rinov/YoutubeKit/pull/110
New Contributors
- @davidgalarza made their first contribution in https://github.com/rinov/YoutubeKit/pull/110
Full Changelog: https://github.com/rinov/YoutubeKit/compare/0.12.0...0.13.0
- 0.12.02025-06-12 · 2025-06-12 00:34 UTC
查看更新说明
What's Changed
- fix: Resolve optional Thumbnails when requesting PlaylistItems by @danperks in https://github.com/rinov/YoutubeKit/pull/103
New Contributors
- @danperks made their first contribution in https://github.com/rinov/YoutubeKit/pull/103
Full Changelog: https://github.com/rinov/YoutubeKit/compare/0.11.0...0.12.0
- 0.11.02025-06-06 · 2025-06-06 02:32 UTC
查看更新说明
What's Changed
- [IMPORTANT] Fix potential race condition and improve code by @Tibimac in https://github.com/rinov/YoutubeKit/pull/108
- Make property videoPublishedAt optional by @Tibimac in https://github.com/rinov/YoutubeKit/pull/105
- Add ability to make VideoListRequest authorized by @Tibimac in https://github.com/rinov/YoutubeKit/pull/107
- Add ability to make PlaylistItemsListRequest authorized by @Tibimac in https://github.com/rinov/YoutubeKit/pull/106
- Add ability to get contentDetails for PlaylistsList by @Tibimac in https://github.com/rinov/YoutubeKit/pull/104
Full Changelog: https://github.com/rinov/YoutubeKit/compare/0.10.0...0.11.0
- 0.10.02024-04-13 · 2024-04-13 10:47 UTC
查看更新说明
Privacy Manifest
Added xcprivacy file for Privacy Manifest
Full Changelog: https://github.com/rinov/YoutubeKit/compare/0.9.0...0.10.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
YoutubeKit
YoutubeKit is an iOS library for the YouTube IFrame Player and YouTube Data API.
References
YoutubeKit is created based on the following references. If you are unsure whether it is a normal behavior or a bug, please check the following documents first.
Example
The Example project demonstrates video playback and Data API requests.
| Example1 | Example2 |
|---|---|
![]() | ![]() |
| Example3 | Example4 |
![]() | ![]() |
YTSwiftyPlayer
YTSwiftyPlayer is a video player that supports Youtube IFrame API.
Features:
- A WKWebView-based IFrame player
- Typed player parameters (
VideoEmbedParameter)
YoutubeDataAPI
This library supports YoutubeDataAPI (v3). For the details is Here.
Available API lists:
- Activity(list)
- Caption(list)
- Channel(list)
- ChannelSections(list)
- Comment(list)
- CommentThreads(list)
- PlaylistItems(list)
- Playlists(list)
- Search(list)
- Subscriptions(list)
- VideoAbuseReportReasons(list)
- VideoCategories(list)
- Videos(list)
Get Started
import UIKit
import YoutubeKit
final class VideoPlayerController: UIViewController {
private var player: YTSwiftyPlayer!
override func viewDidLoad() {
super.viewDidLoad()
// Create a new player
player = YTSwiftyPlayer(
frame: .zero,
playerVars: [
.playsInline(false),
.videoID("_6u6UrtXUEI"),
.loopVideo(true),
.showRelatedVideo(false),
.autoplay(true)
])
view = player
player.delegate = self
// Load video player
player.loadDefaultPlayer()
}
}
// Use the default implementations of the optional delegate callbacks.
extension VideoPlayerController: YTSwiftyPlayerDelegate {}
YTSwiftyPlayerDelegate
YTSwiftyPlayerDelegate provides default implementations of these callbacks:
func playerReady(_ player: YTSwiftyPlayer)
func player(_ player: YTSwiftyPlayer, didUpdateCurrentTime currentTime: Double)
func player(_ player: YTSwiftyPlayer, didChangeState state: YTSwiftyPlayerState)
func player(_ player: YTSwiftyPlayer, didChangePlaybackRate playbackRate: Double)
func player(_ player: YTSwiftyPlayer, didReceiveError error: YTSwiftyPlayerError)
func player(_ player: YTSwiftyPlayer, didReceiveErrorCode code: Int)
func autoplayBlocked(_ player: YTSwiftyPlayer)
func player(_ player: YTSwiftyPlayer, didChangeQuality quality: YTSwiftyVideoQuality)
func apiDidChange(_ player: YTSwiftyPlayer)
func youtubeIframeAPIReady(_ player: YTSwiftyPlayer)
func youtubeIframeAPIFailedToLoad(_ player: YTSwiftyPlayer)
Player identity and failure callbacks
loadDefaultPlayer() and loadPlayerHTML without an explicit URL derive
https://<bundle-id> from the host app's bundle ID for the YouTube Referer.
Custom hosts can supply loadDefaultPlayer(baseURLString:) or the existing baseURLString: argument.
Without a valid bundle ID, the legacy URL is used; supply an explicit app identity URL in that case.
Const.basePlayerURLString and explicit base URLs remain supported.
player(_:didReceiveErrorCode:) reports all error codes, including 153 (missing client identity).
The existing typed didReceiveError callback still runs first for known codes.
autoplayBlocked(_:) reports blocked autoplay; allow the user to start playback with a tap.
Both new callbacks have default implementations, so existing delegates need no changes.
Custom HTML templates should also forward onAutoplayBlocked, as the bundled template does.
The Example logs raw error codes and blocked autoplay for troubleshooting.
See YouTube's client identity requirements.
Call IFrame API during playback.
// Pause the video.
player.pauseVideo()
// Seek to a whole or fractional second.
player.seek(to: 15, allowSeekAhead: true)
player.seek(to: 15.5, allowSeekAhead: true)
// Set a mute.
player.mute()
// Load another video.
player.loadVideo(videoID: "M7lc1UVf-VE")
Int values and method references remain supported; NaN and infinity are ignored. The bundled HTML uses the device viewport width. See GitHub Issues for current bugs and requests.
Get video information using YoutubeDataAPI
First, Get API key from Here.
Next, add this code in your AppDelegate.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set your API key here
YoutubeKit.shared.setAPIKey("Your API key")
return true
}
For iOS-restricted API keys, requests automatically include the host app's bundle ID. See API key restrictions for setup and custom headers.
And then you can use YoutubeDataAPI request like this.
// Get youtube chart ranking
let request = VideoListRequest(part: [.id, .statistics], filter: .chart)
// Send a request.
YoutubeAPI.shared.send(request) { result in
switch result {
case .success(let response):
print(response)
case .failure(let error):
print(error)
}
}
Fetch the next page (Pagination)
var nextPageToken: String?
...
// Send some request
YoutubeAPI.shared.send(request) { [weak self] result in
switch result {
case .success(let response):
// Save nextPageToken
self?.nextPageToken = response.nextPageToken
case .failure(let error):
print(error)
}
}
...
// Set nextPageToken
let request = VideoListRequest(part: [.id], filter: .chart, nextPageToken: nextPageToken)
Authorization Request
If you want authorized request such as a getting your activity in Youtube, you set your access token before sending a request.
To use GoogleSignIn, you can easily get your access token.
pod 'GoogleSignIn'
First, add this code in your AppDelegate.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set your access token for autheticate request
YoutubeKit.shared.setAccessToken("Your access token")
return true
}
And then you can use request requiring authorization, this is an example to get your Youtube activity.
// Get your Youtube activity
let request = ActivityListRequest(part: [.snippet], filter: .mine(true))
// Send a request.
YoutubeAPI.shared.send(request) { result in
switch result {
case .success(let video):
print(video)
case .failure(let error):
print(error)
}
}
Migrating from retired YouTube features
Existing types, enum cases, and arguments are retained with deprecation warnings. Keeping a client API available does not restore a feature removed by YouTube.
| Legacy feature | Current behavior or migration |
|---|---|
ActivityInsertRequest / GuideCategoriesListRequest | Retired by YouTube; no direct replacement |
Filter.ChannelList.categoryID / Filter.SearchList.relatedToVideoID | Retired; use supported ID filters or search queries |
VideoListType.search | Search with the Data API and pass the returned video IDs to the player |
showModestbranding / setPlaybackQuality / availableQualityLevels | Unsupported or ignored; let YouTube control branding and quality |
suggestedQuality argument | Retained for source compatibility; ignored by YouTube |
showRelatedVideo(false) | Limits related videos to the same channel; does not hide them |
Sources: Data API revision history, IFrame revision history, player parameters.
Requirements
iOS 13 or later. SwiftPM tools version is 5.3; the default Swift language mode is 5.
Using a Swift 6 compiler does not require switching the application's language mode to Swift 6.
The networking API retains completion handlers and arbitrary Decodable response types.
Use the .main callback queue for UI updates and synchronize mutable references shared by your app.
ResponseError.unexpectedResponse(Any) is retained; arbitrary payloads are not guaranteed thread-safe.
The Example uses the iOS 13 scene lifecycle.
Development and release verification
Run python3 Scripts/run-tests.py for package regression tests and hosted Example tests.
It selects the latest installed iPhone Simulator; no API key is needed for automated tests.
Use --language-mode 6 to test Swift 6 and --deployment-target 15.0 when required by the SDK.
This override only affects validation builds; package and CocoaPods deployment targets remain iOS 13.
CI runs on Xcode 26 and 27. See release preparation for live playback checks and publishing.
Installation
Swift Package Manager
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/rinov/YoutubeKit.git", from: "0.14.0")
]
CocoaPods (deprecated)
CocoaPods distribution is deprecated; migrate to SwiftPM. The latest version on CocoaPods trunk is 0.9.0, and newer versions are not published there. CocoaPods trunk becomes read-only on December 2, 2026. Until migrating, existing integrations can reference a release tag directly:
pod 'YoutubeKit', :git => 'https://github.com/rinov/YoutubeKit.git', :tag => '0.14.0'
Upgrading from 0.9.0 requires iOS 13 (0.9.0 supported iOS 11). Applications that still support iOS 11 or 12 must remain on a compatible older version.
Carthage (legacy)
The current repository has no shared framework target; use SwiftPM for new integrations. Existing users should pin their validated version and verify resource loading before migrating.
Author
rinov · Twitter · rinov[at]rinov.jp
License
YoutubeKit is available under the MIT license.



