Ejemplo n.º 1
0
        async Task RequestStorefrontCountryCodeAsync()
        {
            string countryCode;

            if (SKCloudServiceController.AuthorizationStatus == SKCloudServiceAuthorizationStatus.Authorized)
            {
                if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
                {
                    /*
                     * On iOS 11.0 or later, if the
                     * `SKCloudServiceController.authorizationStatus()`
                     * is `.authorized` then you can request the
                     * storefront country code.
                     */
                    countryCode = (await CloudServiceController.RequestStorefrontCountryCodeAsync()).ToString();
                }
                else
                {
                    countryCode = await AppleMusicManager.PerformAppleMusicGetUserStorefrontAsync(UserToken);
                }
            }
            else
            {
                countryCode = await DetermineRegion();
            }

            if (string.IsNullOrWhiteSpace(countryCode))
            {
                throw new ArgumentNullException(nameof(countryCode), "Unexpected value from SKCloudServiceController for storefront country code.");
            }

            CloudServiceStorefrontCountryCode = countryCode;

            InvokeOnMainThread(() => NSNotificationCenter.DefaultCenter.PostNotificationName(CloudServiceDidUpdateNotification, null));
        }
Ejemplo n.º 2
0
        async Task RequestUserTokenAsync()
        {
            var developerToken = AppleMusicManager.FetchDeveloperToken();

            if (developerToken == null)
            {
                throw new ArgumentNullException(nameof(developerToken), "Developer Token not configured. See README for more details.");
            }

            if (SKCloudServiceController.AuthorizationStatus != SKCloudServiceAuthorizationStatus.Authorized)
            {
                return;
            }

            string token;

            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                token = await CloudServiceController.RequestUserTokenAsync(developerToken);
            }
            else
            {
                token = await CloudServiceController.RequestPersonalizationTokenAsync(developerToken);
            }

            if (string.IsNullOrWhiteSpace(token))
            {
                Console.WriteLine("Unexpected value from SKCloudServiceController for user token.");
                return;
            }

            UserToken = token;

            // Store the Music User Token for future use in your application.
            var userDefaults = NSUserDefaults.StandardUserDefaults;

            userDefaults.SetString(token, UserTokenUserDefaultsKey);
            userDefaults.Synchronize();

            if (string.IsNullOrWhiteSpace(CloudServiceStorefrontCountryCode))
            {
                await RequestStorefrontCountryCodeAsync();
            }

            InvokeOnMainThread(() => NSNotificationCenter.DefaultCenter.PostNotificationName(CloudServiceDidUpdateNotification, null));
        }
Ejemplo n.º 3
0
        async Task RequestCloudServiceCapabilitiesAsync()
        {
            CloudServiceCapabilities = await CloudServiceController.RequestCapabilitiesAsync();

            InvokeOnMainThread(() => NSNotificationCenter.DefaultCenter.PostNotificationName(CloudServiceDidUpdateNotification, null));
        }