From 6b31b2bf40919748b890eb4b00c1291e823690bd Mon Sep 17 00:00:00 2001 From: romain petit Date: Thu, 4 Aug 2022 12:25:32 +0200 Subject: [PATCH] fix(cocoapods) handle assets for cocoapods from sources folder --- ApiVideoPlayer.podspec | 4 +-- Package.resolved | 4 +-- Package.swift | 3 ++- .../ApiVideoPlayerResources.swift | 25 +++++++++++++++++++ .../Media.xcassets/Contents.json | 0 .../pause-primary.imageset/Contents.json | 0 .../pause-primary.imageset/pause-primary.svg | 0 .../play-primary.imageset/Contents.json | 0 .../play-primary.imageset/play-primary.svg | 0 .../replay-primary.imageset/Contents.json | 0 .../replay-primary.svg | 0 .../ApiVideoPlayer/View/VodControlsView.swift | 2 +- 12 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 Sources/ApiVideoPlayer/ApiVideoPlayerResources.swift rename Sources/ApiVideoPlayer/{ => Resources}/Media.xcassets/Contents.json (100%) rename Sources/ApiVideoPlayer/{ => Resources}/Media.xcassets/pause-primary.imageset/Contents.json (100%) rename Sources/ApiVideoPlayer/{ => Resources}/Media.xcassets/pause-primary.imageset/pause-primary.svg (100%) rename Sources/ApiVideoPlayer/{ => Resources}/Media.xcassets/play-primary.imageset/Contents.json (100%) rename Sources/ApiVideoPlayer/{ => Resources}/Media.xcassets/play-primary.imageset/play-primary.svg (100%) rename Sources/ApiVideoPlayer/{ => Resources}/Media.xcassets/replay-primary.imageset/Contents.json (100%) rename Sources/ApiVideoPlayer/{ => Resources}/Media.xcassets/replay-primary.imageset/replay-primary.svg (100%) diff --git a/ApiVideoPlayer.podspec b/ApiVideoPlayer.podspec index 1bb31039..5ee2dbd3 100644 --- a/ApiVideoPlayer.podspec +++ b/ApiVideoPlayer.podspec @@ -11,8 +11,8 @@ Pod::Spec.new do |s| s.ios.deployment_target = '11.0' s.swift_version = '5.0' - s.source_files = 'Sources/**/*' - s.resources = 'Sources/*.xcassets/*' + s.source_files = 'Sources/**/*.{swift, plist}' + s.resources = 'Sources/**/*.{storyboard,xib,xcassets,json,png}' s.dependency "ApiVideoPlayerAnalytics", "1.0.4" end diff --git a/Package.resolved b/Package.resolved index a898d4e1..1db53a8d 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apivideo/api.video-ios-player-analytics.git", "state" : { - "revision" : "f8b5eb5ff6c6899b03f7049e88274caea5d67857", - "version" : "1.0.3" + "revision" : "c34d58405161c8055ee14b33af7a06ff4e55d00a", + "version" : "1.0.4" } } ], diff --git a/Package.swift b/Package.swift index c4668c54..7411b4f4 100644 --- a/Package.swift +++ b/Package.swift @@ -25,7 +25,8 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "ApiVideoPlayer", - dependencies: [.product(name: "ApiVideoPlayerAnalytics", package: "api.video-ios-player-analytics")] + dependencies: [.product(name: "ApiVideoPlayerAnalytics", package: "api.video-ios-player-analytics")], + resources: [.process("Resources")] ), .testTarget( name: "ApiVideoPlayerTests", diff --git a/Sources/ApiVideoPlayer/ApiVideoPlayerResources.swift b/Sources/ApiVideoPlayer/ApiVideoPlayerResources.swift new file mode 100644 index 00000000..2eb933b2 --- /dev/null +++ b/Sources/ApiVideoPlayer/ApiVideoPlayerResources.swift @@ -0,0 +1,25 @@ +import Foundation + +public final class ApiVideoPlayerResources { + public static let resourceBundle: Bundle = { + let candidates = [ + // Bundle should be present here when the package is linked into an App. + Bundle.main.resourceURL, + + // Bundle should be present here when the package is linked into a framework. + Bundle(for: ApiVideoPlayerResources.self).resourceURL, + ] + + let bundleName = "ApiVideoPlayer_ApiVideoPlayer" + + for candidate in candidates { + let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle") + if let bundle = bundlePath.flatMap(Bundle.init(url:)) { + return bundle + } + } + + // Return whatever bundle this code is in as a last resort. + return Bundle(for: ApiVideoPlayerResources.self) + }() +} diff --git a/Sources/ApiVideoPlayer/Media.xcassets/Contents.json b/Sources/ApiVideoPlayer/Resources/Media.xcassets/Contents.json similarity index 100% rename from Sources/ApiVideoPlayer/Media.xcassets/Contents.json rename to Sources/ApiVideoPlayer/Resources/Media.xcassets/Contents.json diff --git a/Sources/ApiVideoPlayer/Media.xcassets/pause-primary.imageset/Contents.json b/Sources/ApiVideoPlayer/Resources/Media.xcassets/pause-primary.imageset/Contents.json similarity index 100% rename from Sources/ApiVideoPlayer/Media.xcassets/pause-primary.imageset/Contents.json rename to Sources/ApiVideoPlayer/Resources/Media.xcassets/pause-primary.imageset/Contents.json diff --git a/Sources/ApiVideoPlayer/Media.xcassets/pause-primary.imageset/pause-primary.svg b/Sources/ApiVideoPlayer/Resources/Media.xcassets/pause-primary.imageset/pause-primary.svg similarity index 100% rename from Sources/ApiVideoPlayer/Media.xcassets/pause-primary.imageset/pause-primary.svg rename to Sources/ApiVideoPlayer/Resources/Media.xcassets/pause-primary.imageset/pause-primary.svg diff --git a/Sources/ApiVideoPlayer/Media.xcassets/play-primary.imageset/Contents.json b/Sources/ApiVideoPlayer/Resources/Media.xcassets/play-primary.imageset/Contents.json similarity index 100% rename from Sources/ApiVideoPlayer/Media.xcassets/play-primary.imageset/Contents.json rename to Sources/ApiVideoPlayer/Resources/Media.xcassets/play-primary.imageset/Contents.json diff --git a/Sources/ApiVideoPlayer/Media.xcassets/play-primary.imageset/play-primary.svg b/Sources/ApiVideoPlayer/Resources/Media.xcassets/play-primary.imageset/play-primary.svg similarity index 100% rename from Sources/ApiVideoPlayer/Media.xcassets/play-primary.imageset/play-primary.svg rename to Sources/ApiVideoPlayer/Resources/Media.xcassets/play-primary.imageset/play-primary.svg diff --git a/Sources/ApiVideoPlayer/Media.xcassets/replay-primary.imageset/Contents.json b/Sources/ApiVideoPlayer/Resources/Media.xcassets/replay-primary.imageset/Contents.json similarity index 100% rename from Sources/ApiVideoPlayer/Media.xcassets/replay-primary.imageset/Contents.json rename to Sources/ApiVideoPlayer/Resources/Media.xcassets/replay-primary.imageset/Contents.json diff --git a/Sources/ApiVideoPlayer/Media.xcassets/replay-primary.imageset/replay-primary.svg b/Sources/ApiVideoPlayer/Resources/Media.xcassets/replay-primary.imageset/replay-primary.svg similarity index 100% rename from Sources/ApiVideoPlayer/Media.xcassets/replay-primary.imageset/replay-primary.svg rename to Sources/ApiVideoPlayer/Resources/Media.xcassets/replay-primary.imageset/replay-primary.svg diff --git a/Sources/ApiVideoPlayer/View/VodControlsView.swift b/Sources/ApiVideoPlayer/View/VodControlsView.swift index af3a9c22..bdff3f19 100644 --- a/Sources/ApiVideoPlayer/View/VodControlsView.swift +++ b/Sources/ApiVideoPlayer/View/VodControlsView.swift @@ -307,7 +307,7 @@ private func setPlayBtnIcon(iconName: String) { if #available(tvOS 13.0, *) { - playPauseButton.setImage(UIImage(named: iconName, in: Bundle.module, compatibleWith: nil), for: .normal) + playPauseButton.setImage(UIImage(named: iconName, in: ApiVideoPlayerResources.resourceBundle, compatibleWith: nil), for: .normal) } else { // Fallback on earlier versions }