public Task RequestAccess() { var tcs = new TaskCompletionSource <object>(); SKCloudServiceController.RequestAuthorization(_ => { tcs.SetResult(null); }); return(tcs.Task); }
public AuthorizationManager(AppleMusicManager appleMusicManager) { AppleMusicManager = appleMusicManager; CloudServiceController = new SKCloudServiceController(); CloudServiceCapabilities = new SKCloudServiceCapability(); /* * It is important that your application listens to the * `CloudServiceCapabilitiesDidChangeNotification` and * `StorefrontCountryCodeDidChangeNotification` notifications * so that your application can update its state and * functionality when these values change if needed. */ var notificationCenter = NSNotificationCenter.DefaultCenter; CloudServiceCapabilitiesDidChangeNotificationToken = notificationCenter.AddObserver(SKCloudServiceController.CloudServiceCapabilitiesDidChangeNotification, async(obj) => await RequestCloudServiceCapabilitiesAsync()); if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { StorefrontCountryCodeDidChangeNotificationToken = notificationCenter.AddObserver(SKCloudServiceController.StorefrontCountryCodeDidChangeNotification, async(obj) => await RequestStorefrontCountryCodeAsync()); } /* * If the application has already been authorized in a * previous run or manually by the user then it can * request the current set of `SKCloudServiceCapability` * and Storefront Identifier. */ if (SKCloudServiceController.AuthorizationStatus == SKCloudServiceAuthorizationStatus.Authorized) { Task.Factory.StartNew(async() => { await RequestCloudServiceCapabilitiesAsync(); // Retrieve the Music User Token for use in the application // if it was stored from a previous run. if (NSUserDefaults.StandardUserDefaults.StringForKey(UserTokenUserDefaultsKey) is string token) { UserToken = token; await RequestStorefrontCountryCodeAsync(); } else // The token was not stored previously then request one. { await RequestUserTokenAsync(); } }); } }
public async Task RequestCloudServiceAuthorizationAsync() { /* * An application should only ever call * `SKCloudServiceController.RequestAuthorization` when * their current authorization is * `SKCloudServiceAuthorizationStatus.NotDetermined` */ if (SKCloudServiceController.AuthorizationStatus != SKCloudServiceAuthorizationStatus.NotDetermined) { return; } /* * `SKCloudServiceController.RequestAuthorizationAsync ()` * triggers a prompt for the user asking if they wish to * allow the application that requested authorization * access to the device's cloud services information. * This allows the application to query information such * as the what capabilities the currently authenticated * iTunes Store account has and if the account is * eligible for an Apple Music Subscription Trial. * * This prompt will also include the value provided in * the application's Info.plist for the * `NSAppleMusicUsageDescription` key. This usage * description should reflect what the application * intends to use this access for. */ var authorizationStatus = await SKCloudServiceController.RequestAuthorizationAsync(); switch (authorizationStatus) { case SKCloudServiceAuthorizationStatus.Authorized: await RequestCloudServiceCapabilitiesAsync(); await RequestUserTokenAsync(); break; default: break; } InvokeOnMainThread(() => NSNotificationCenter.DefaultCenter.PostNotificationName(AuthorizationDidUpdateNotification, null)); }