A binding to a Boolean value that you can set to true
to show a sheet with subscription offers for Apple Music.
musicSubscriptionOffer(isPresented:options:onLoadCompletion:)
isPresented
binding is true
.Availability 有効性
- iOS 15.0+
- iPadOS 15.0+
- macOS 12.0+
- Mac Catalyst 15.0+
Technology
-
Swift
UI SwiftUI
Declaration 宣言
Parameters パラメータ
isPresented
options
Options to use for loading the subscription offer for Apple Music.
onLoadCompletion
The function to call upon completing the initial loading process for this subscription offer. The subscription offer UI becomes visible when it calls this function with the error argument as
nil
. If there is an error in the loading process, the subscription offer calls this function with a non-nil
error, and it resets theis
binding toPresented false
.
Discussion 議論
The example below displays a simple button that the user can activate to begin presenting subscription offers for Apple Music. The action handler of this button initiates the presentation of those offers by setting the is
variable to true
.
struct MusicSubscriptionOfferButton: View {
var isShowingOffer = false
var body: some View {
Button("Apple Music Subscription Offer") {
isShowingOffer = true
}
.musicSubscriptionOffer(isPresented: $isShowingOffer)
}
}
You can also configure the Apple Music subscription offer by creating an instance of Music
, setting relevant properties on it, and passing it to .music
. For example, to present contextual offers that highlight a specific album, you can configure the subscription offer like the following:
struct MusicSubscriptionOfferButton: View {
var album: Album
var isShowingOffer = false
var offerOptions = MusicSubscriptionOffer.Options(
affiliateToken: "<affiliate_token>",
campaignToken: "<campaign_token>"
)
var body: some View {
Button("Apple Music Subscription Offer") {
offerOptions.itemID = album.id
isShowingOffer = true
}
.musicSubscriptionOffer(
isPresented: $isShowingOffer,
options: offerOptions
)
}
}
The initial value of offer
includes relevant tokens (affiliate and campaign tokens) that allow you to receive compensation for referring new Apple Music subscribers. For more information, see this presentation of the Apple Services Performance Partners Program.
You may also set is
to false
to programmatically dismiss the subscription offer (or to abort its loading process).