Esempio n. 1
0
        public async Task RequestMediaLibraryAuthorizationAsync()
        {
            /*
             * An application should only ever call
             * `MPMediaLibrary.AuthorizationStatus` when their current
             * authorization is `MPMediaLibraryAuthorizationStatus.NotDetermined`
             */
            if (MPMediaLibrary.AuthorizationStatus != MPMediaLibraryAuthorizationStatus.NotDetermined)
            {
                return;
            }

            /*
             * `MPMediaLibrary.RequestAuthorizationAsync ()` triggers a
             * prompt for the user asking if they wish to allow the
             * application that requested authorization access to
             * the device's media library.
             *
             * 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.
             */
            await MPMediaLibrary.RequestAuthorizationAsync();

            InvokeOnMainThread(() => NSNotificationCenter.DefaultCenter.PostNotificationName(CloudServiceDidUpdateNotification, null));
        }
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ConfigureSearchController();

            TableView.Source = new TableSource(this);

            TableView.TableFooterView = new UIView();
            TableView.BackgroundView  = new UIView();

            selectedMediaItems = new List <MPMediaItem>();

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 3))
            {
                var status = await MPMediaLibrary.RequestAuthorizationAsync();

                if (status == MPMediaLibraryAuthorizationStatus.Authorized)
                {
                    LoadMediaItemsForMediaTypeAsync(MPMediaType.Music);
                }
                else
                {
                    DisplayMediaLibraryError();
                }
            }
            else
            {
                LoadMediaItemsForMediaTypeAsync(MPMediaType.Music);
            }
        }