广告牌 (Billboard) 是一个模块,允许独立开发者在其应用中加入广告精选内容。它独特的特性在于,它在展示广告的同时,不使用跟踪措施或不必要的 Cookie。这样,你的用户仍然会被广告打扰,但不会有那些令人讨厌的东西,因此你可以获得一个免费的 "移除广告" 作为你高级订阅的卖点。
这些广告不会产生收入或跟踪任何信息
可在 iOS 16+、tvOS 17+ 和 visionOS 1+ 上使用。
https://github.com/hiddevdploeg/Billboard
。import Billboard
Billboard 提供了一种简单的方法,可以在任何 SwiftUI View
上显示广告覆盖层。 这是一个简单的例子
@State private var showRandomAdvert = false
ContentView()
.showBillboard(when: $showRandomAdvert) {
// Replace this view with your Paywall
Text("Your Paywall goes here")
}
或者,你可以自定义 BillboardView
并以任何适合你应用的方式定位它。 此视图需要一个 BillboardAd
、一个 BillboardConfiguration
(可选)和一个代表你的付费墙的视图
@State private var advertisement: BillboardAd? = nil
@StateObject var viewModel = BillboardViewModel()
ContentView()
.task {
let newAdvert = try? await viewModel.fetchRandomAd()
advertisement = newAdvert
}
.fullScreenCover(item: $advertisement) { advert in
BillboardView(advert: advert, paywall: { Text("Paywall") })
}
提示:当你运行应用的调试版本时,你可以点击计时器立即显示关闭按钮。
如果你不喜欢全屏视图,但更喜欢在内容中显示一个较小的横幅,你现在也可以这样做! 只需在你喜欢的任何位置添加一个 BillboardBannerView
。
@State private var advert: BillboardAd? = nil
ContentView()
.safeAreaInset(edge: .bottom) {
if let advert {
BillboardBannerView(advert: advert)
.padding()
}
}
默认情况下,它带有一个阴影,你可以通过更改 includeShadow
值来选择不包含阴影。 这是一个如何在列表中包含 BillboardBannerView
的示例
@State private var advert: BillboardAd? = nil
List {
if let advert {
Section {
BillboardBannerView(advert: advert, includeShadow: false)
.listRowBackground(Color.clear)
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
// Rest of the list...
}
你还可以通过将 hideDismissButtonAndTimer: true
添加到你的 BillboardBannerView
来隐藏关闭按钮,从而获得一个持久横幅。
Billboard 允许你定义一些配置,以更好地满足你的需求。
public struct BillboardConfiguration {
/// The URL pointing to the JSON in the `BillboardAdResponse` format.
public let adsJSONURL: URL?
/// Enable or disable haptics
public let allowHaptics: Bool
/// The duration of the advertisement
public let duration: TimeInterval
/// 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] = []) {
self.adsJSONURL = adsJSONURL
self.allowHaptics = allowHaptics
self.duration = advertDuration
self.excludedIDs = excludedIDs
}
}
这也允许你使用自己的广告来源,这些广告来源遵循 BillboardAdResponse
格式。
@State private var showRandomAdvert = false
let config = BillboardConfiguration(
adsJSONURL: URL(string: "YOUR-OWN-SOURCE"),
allowHaptics: false,
advertDuration: 30.0,
excludedIDs: ["1234567890"]
)
ContentView()
.showBillboard(when: $showRandomAdvert, configuration: config) {
// Replace this view with your Paywall
Text("Your Paywall goes here")
}
这是一个你的源列表可能看起来的例子。
{
"ads" : [
{
"appStoreID" : "1574243765",
"name" : "NowPlaying",
"title": "Learn everything about any song",
"description" : "A music companion app that lets you discover the stories behind and song, album or artist.",
"media": "https://pub-378e0dd96b5343108a04317ebddebb4e.r2.dev/nowplaying.png",
"backgroundColor" : "344442",
"textColor" : "EFDED7",
"tintColor" : "EFDED7",
"fullscreen": false,
"transparent": true,
"adCategory": "music"
}
]
}
提交你的应用,以便作为广告展示给使用 Billboard 包来展示广告的每个人。每个广告在包含之前都将经过审核。
随意使用 Figma 的 Billboard 模板来调整和预览宣传内容。
当 BillboardAd.fullscreen
设置为 true
时,广告的媒体将覆盖整个视图。 如果媒体是照片而不是视觉效果,这将非常有效。 请考虑照片的主题必须位于中心,这将确保它始终可见。
你可以在示例 App 中找到当前使用的所有广告列表。
tundsdev 提供 CachedImage 实现
这个库是由 Hidde van der Ploeg 创建的。 欢迎在 Twitter 或 Mastodon 上联系我。
Billboard 在 MIT 许可下可用。
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.