<!--
{
  "documentType" : "article",
  "framework" : "StoreKit",
  "identifier" : "/documentation/StoreKit/offering-apple-music-subscription-in-your-app",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Offering Apple Music Subscription in Your App"
}
-->

# Offering Apple Music Subscription in Your App

Allow eligible customers to subscribe to Apple Music.

## Discussion

With an Apple Music membership, customers can play songs from the entire Apple Music catalog or access their iCloud music library across all their devices. You can offer users the option to sign up for an Apple Music subscription directly from your app by following these steps:

1. Request Apple Music Library access from the customer.
2. Determine if the customer is eligible for an Apple Music subscription.
3. Present the sign-up subscription offer if the customer is eligible.

### Request Apple Music Library Access

The user must grant permission before your app can access Apple Music library. See [Requesting Access to Apple Music Library](/documentation/StoreKit/requesting-access-to-apple-music-library) for details. Use [`authorizationStatus()`](/documentation/StoreKit/SKCloudServiceController/authorizationStatus()) to determine your app’s authorization status. If the authorization status is [`SKCloudServiceAuthorizationStatus.authorized`](/documentation/StoreKit/SKCloudServiceAuthorizationStatus/authorized), your app can check if the user is eligible for an Apple Music subscription offer.

```swift
SKCloudServiceController.authorizationStatus() == .authorized
```

> Important:
> When the Music app is absent on the user’s device, ``doc://com.apple.storekit/documentation/StoreKit/SKCloudServiceSetupViewController/load(options:completionHandler:)`` fails to load.

### Determine if the User is Eligible for an Apple Music Subscription

After getting Apple Music access from the user, call [`requestCapabilities(completionHandler:)`](/documentation/StoreKit/SKCloudServiceController/requestCapabilities(completionHandler:)) on an instance of [`SKCloudServiceController`](/documentation/StoreKit/SKCloudServiceController) to query the user’s capabilities. Then, inspect the `capabilities` parameter of this method to determine eligibility. See [Determining a person’s Apple Music capabilities](/documentation/StoreKit/determining-a-person-s-apple-music-capabilities) for details. A user has an active subscription to Apple Music when `capabilities` contains [`musicCatalogPlayback`](/documentation/StoreKit/SKCloudServiceCapability/musicCatalogPlayback). A user is eligible for the offer when `capabilities` doesn’t include [`musicCatalogPlayback`](/documentation/StoreKit/SKCloudServiceCapability/musicCatalogPlayback) but contains [`musicCatalogSubscriptionEligible`](/documentation/StoreKit/SKCloudServiceCapability/musicCatalogSubscriptionEligible).

```swift
let controller = SKCloudServiceController()
controller.requestCapabilities { (capabilities: SKCloudServiceCapability, error: Error?) in
    guard error == nil else { return }

    if capabilities.contains(.musicCatalogSubscriptionEligible) && !capabilities.contains(.musicCatalogPlayback) {
        // Allows subscription to the Apple Music catalog.
    }
}
```

### Present the Offer to Subscribe for Apple Music

For users who are eligible for an Apple Music subscription, use the following steps to allow users to sign up for it.

First, create a dictionary with an [`action`](/documentation/StoreKit/SKCloudServiceSetupOptionsKey/action) key to [`subscribe`](/documentation/StoreKit/SKCloudServiceSetupAction/subscribe):

```swift
let options: [SKCloudServiceSetupOptionsKey: Any] = [.action: SKCloudServiceSetupAction.subscribe]
```

If you have an [iTunes Store affiliate account](https://help.apple.com/app-store-connect/#/itcfa7936330), you can add the [`affiliateToken`](/documentation/StoreKit/SKCloudServiceSetupOptionsKey/affiliateToken) key to the dictionary to earn commision if the user subscribes:

```swift
let affiliateToken = "Your_Affiliate_Token"
let options: [SKCloudServiceSetupOptionsKey: Any] = [.action: SKCloudServiceSetupAction.subscribe, .affiliateToken: affiliateToken]
```

By default, the setup view is configured with the [`messageIdentifier`](/documentation/StoreKit/SKCloudServiceSetupOptionsKey/messageIdentifier) key set to [`join`](/documentation/StoreKit/SKCloudServiceSetupMessageIdentifier/join). Add [`messageIdentifier`](/documentation/StoreKit/SKCloudServiceSetupOptionsKey/messageIdentifier) to the dictionary and set it to [`addMusic`](/documentation/StoreKit/SKCloudServiceSetupMessageIdentifier/addMusic), [`connect`](/documentation/StoreKit/SKCloudServiceSetupMessageIdentifier/connect), or [`playMusic`](/documentation/StoreKit/SKCloudServiceSetupMessageIdentifier/playMusic) if you wish to change the default message that your app shows to the user:

```swift
let options: [SKCloudServiceSetupOptionsKey: Any] = [.action: SKCloudServiceSetupAction.subscribe, .messageIdentifier: SKCloudServiceSetupMessageIdentifier.addMusic]
```

Next, create an [`SKCloudServiceSetupViewController`](/documentation/StoreKit/SKCloudServiceSetupViewController) object and set the view controller class as its delegate:

```swift
let controller = SKCloudServiceSetupViewController()
controller.delegate = self
```

Then, pass the dictionary to the [`load(options:completionHandler:)`](/documentation/StoreKit/SKCloudServiceSetupViewController/load(options:completionHandler:)) method of the [`SKCloudServiceSetupViewController`](/documentation/StoreKit/SKCloudServiceSetupViewController) object. Finally, present the [`SKCloudServiceSetupViewController`](/documentation/StoreKit/SKCloudServiceSetupViewController) object modally from your app:

```swift
controller.load(options: options) { [weak self] (result: Bool, error: Error?) in
   guard error == nil else { return }
   
    if result {
        self?.present(controller, animated: true, completion: nil)
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)