Determining a person’s Apple Music capabilities
Determine which Apple Music capabilities are available on a customer’s device.
Overview
After you request the user’s permission to access their Apple Music library (see Requesting Access to Apple Music Library), you confirm that authorization and then identify Apple Music capabilities on the user’s device.
Confirm Whether the User Authorized Access to Apple Music Library
Use SKCloudServiceController’s authorizationStatus() to check whether the user has authorized access to Apple Music Library. If the authorization status is SKCloudServiceAuthorizationStatus.notDetermined, call SKCloudServiceController’s requestAuthorization(_:) to prompt the user for access.
If the authorization status is SKCloudServiceAuthorizationStatus.authorized, your app can proceed to determine which Apple Music capabilities (musicCatalogPlayback, musicCatalogSubscriptionEligible, or addToCloudMusicLibrary) are available on the user’s device.
Create a Cloud Service Controller and Its Handler to Fetch Capabilities
First, create an SKCloudServiceController object:
Then call its requestCapabilities(completionHandler:) method to fetch the current Apple Music capabilities, as described in the sections that follow.
Check for the Capability to Play Apple Music Content
If you want your app to play Apple Music content, check whether capabilities includes musicCatalogPlayback:
Check for the Subscription-Eligible Capability
A user is eligible for an Apple Music subscription offer when capabilities doesn’t include musicCatalogPlayback but contains musicCatalogSubscriptionEligible. If you want your app to present the user with an offer to subscribe to Apple Music, check capabilities for these features:
You can present the offer using SKCloudServiceSetupViewController.
Check for the Capability to Add Songs to the User’s iCloud Music Library
If you want your app to add tracks to the user’s iCloud music library, check whether capabilities includes addToCloudMusicLibrary: