Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tvOS support and other fixes #38

Merged
merged 11 commits into from
Nov 29, 2024
10 changes: 8 additions & 2 deletions Example/BillboardExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,19 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.modumhq.BillboardExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,3";
};
name = Debug;
};
Expand All @@ -310,16 +313,19 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.modumhq.BillboardExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,3";
};
name = Release;
};
Expand Down
25 changes: 14 additions & 11 deletions Example/BillboardExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ struct ContentView: View {
@StateObject var premium = PremiumStore()

@State private var showRandomAdvert = false
@State private var adtoshow :BillboardAd? = nil
@State private var allAds : [BillboardAd] = []
@State private var adtoshow: BillboardAd? = nil
@State private var allAds: [BillboardAd] = []
@State private var bannerAd: BillboardAd? = nil

let config = BillboardConfiguration(advertDuration: 5)

var body: some View {
NavigationStack {
List {
if let advert = allAds.randomElement() {
if let bannerAd {
Section {
BillboardBannerView(advert: advert, hideDismissButtonAndTimer: true)
BillboardBannerView(advert: bannerAd, hideDismissButtonAndTimer: true)
.listRowBackground(Color.clear)
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
Expand Down Expand Up @@ -62,11 +63,11 @@ struct ContentView: View {
}
}
}
.font(.compatibleSystem(.body, design: .rounded, weight: .medium))
.font(.system(.body, design: .rounded, weight: .medium))
}
.safeAreaInset(edge: .bottom, content: {
if let advert = allAds.randomElement() {
BillboardBannerView(advert: advert)
if let bannerAd {
BillboardBannerView(advert: bannerAd)
.padding()

}
Expand All @@ -75,14 +76,15 @@ struct ContentView: View {
Task {
if let allAds = try? await BillboardViewModel.fetchAllAds(from: config.adsJSONURL!) {
self.allAds = allAds
self.bannerAd = allAds.randomElement()
}
}
}
.onChange(of: premium.didBuyPremium) { newValue in
if newValue {
showRandomAdvert = !newValue
.onChange(of: premium.didBuyPremium, {
if premium.didBuyPremium {
showRandomAdvert = !premium.didBuyPremium
}
}
})
.showBillboard(when: $showRandomAdvert) {
// Replace this view with your Paywall
VStack {
Expand All @@ -102,6 +104,7 @@ struct ContentView: View {

if let allAds = try? await BillboardViewModel.fetchAllAds(from: config.adsJSONURL!) {
self.allAds = allAds
bannerAd = allAds.randomElement()
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// swift-tools-version: 5.7
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Billboard",
platforms: [
.iOS(.v15),
.tvOS(.v16)
.iOS(.v17),
.visionOS(.v1),
.tvOS(.v17)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
Expand All @@ -21,5 +22,6 @@ let package = Package(
.testTarget(
name: "BillboardTests",
dependencies: ["Billboard"]),
]
],
swiftLanguageModes: [.v5]
)
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Billboard is a module that enables the incorporation of advertisement highlights


## Installation
Ready to use on iOS 15+.
Ready to use on iOS 16+, tvOS 17+ and visionOS 1+.

1. In Xcode, select **Add Packages…** from the File menu.
2. Enter `https://github.com/hiddevdploeg/Billboard` in the search field.
Expand Down Expand Up @@ -171,7 +171,8 @@ Here's an example of how your source list could look like.
"textColor" : "EFDED7",
"tintColor" : "EFDED7",
"fullscreen": false,
"transparent": true
"transparent": true,
"adCategory": "music"
}
]
}
Expand Down
60 changes: 0 additions & 60 deletions Sources/Billboard/CachedImage/CachedImageManager.swift

This file was deleted.

18 changes: 0 additions & 18 deletions Sources/Billboard/Utilities/Font+iOS15.swift

This file was deleted.

16 changes: 0 additions & 16 deletions Sources/Billboard/Utilities/Logger+Ext.swift

This file was deleted.

32 changes: 0 additions & 32 deletions Sources/Billboard/Views/BillboardDismissButton.swift

This file was deleted.

38 changes: 0 additions & 38 deletions Sources/Billboard/Views/BillboardTextView.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ public struct BillboardConfiguration {
/// Provide a list of Apple ID's that you want to exclude from showing up (e.g. your own app)
public let excludedIDs : [String]

public init(adsJSONURL: URL? = URL(string:"https://billboard-source.vercel.app/ads.json"),
allowHaptics: Bool = true,
advertDuration: TimeInterval = 15.0, excludedIDs: [String] = []) {
/// All Categories that should be included in the ads that are shown
public let categories : [String]

public init(
adsJSONURL: URL? = URL(string:"https://billboard-source.vercel.app/ads.json"),
allowHaptics: Bool = true,
advertDuration: TimeInterval = 15.0,
excludedIDs: [String] = [],
categories: [AdCategory] = AdCategory.allCases
) {
self.adsJSONURL = adsJSONURL
self.allowHaptics = allowHaptics
self.duration = advertDuration
self.excludedIDs = excludedIDs
self.categories = categories.map { $0.rawValue }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public final class BillboardViewModel : ObservableObject {
}
}

public static func fetchRandomAd(excludedIDs: [String] = []) async throws -> BillboardAd? {
public static func fetchRandomAd(
excludedIDs: [String] = [],
categories: [AdCategory] = AdCategory.allCases
) async throws -> BillboardAd? {
guard let url = BillboardConfiguration().adsJSONURL else {
return nil
}
Expand All @@ -50,7 +53,12 @@ public final class BillboardViewModel : ObservableObject {
let (data, _) = try await session.data(from: url)
let decoder = JSONDecoder()
let response = try decoder.decode(BillboardAdResponse.self, from: data)
let filteredAds = response.ads.filter({ !excludedIDs.contains($0.appStoreID) })
var filteredAds = response.ads.filter({ !excludedIDs.contains($0.appStoreID) })

if categories.count != AdCategory.allCases.count {
filteredAds = filteredAds.filter({ categories.contains($0.category) })
}

let adToShow = filteredAds.randomElement()

if let adToShow {
Expand All @@ -74,15 +82,25 @@ public final class BillboardViewModel : ObservableObject {
return nil
}

public static func fetchRandomAd(from url: URL, excludedIDs: [String] = []) async throws -> BillboardAd? {
public static func fetchRandomAd(
from url: URL,
excludedIDs: [String] = [],
categories: [AdCategory] = AdCategory.allCases
) async throws -> BillboardAd? {
let session = URLSession(configuration: BillboardViewModel.networkConfiguration)
session.sessionDescription = "Fetching Billboard Ad"

do {
let (data, _) = try await session.data(from: url)
let decoder = JSONDecoder()
let response = try decoder.decode(BillboardAdResponse.self, from: data)
let filteredAds = response.ads.filter({ !excludedIDs.contains($0.appStoreID) })

var filteredAds = response.ads.filter({ !excludedIDs.contains($0.appStoreID) })

if categories.count != AdCategory.allCases.count {
filteredAds = filteredAds.filter({ categories.contains($0.category) })
}

let adToShow = filteredAds.randomElement()

if let adToShow {
Expand Down
Loading
Loading