public static void RequestMediaLibraryPermission(bool assert_granted = false)
    {
        if (!CheckXcodeVersion(7, 3))
        {
            if (IgnoreTestThatRequiresSystemPermissions())
            {
                NUnit.Framework.Assert.Ignore("This test might show a dialog to ask for permission to access the media library, but the API to check if a dialog is required (or to request permission) is not available in this OS version.");
            }
            return;
        }

        if (MPMediaLibrary.AuthorizationStatus == MPMediaLibraryAuthorizationStatus.NotDetermined)
        {
            if (IgnoreTestThatRequiresSystemPermissions())
            {
                NUnit.Framework.Assert.Ignore("This test would show a dialog to ask for permission to access the media library.");
            }

            MPMediaLibrary.RequestAuthorization((access) =>
            {
                Console.WriteLine("Media library permission: {0}", access);
            });
        }

        switch (MPMediaLibrary.AuthorizationStatus)
        {
        case MPMediaLibraryAuthorizationStatus.Denied:
        case MPMediaLibraryAuthorizationStatus.Restricted:
            if (assert_granted)
            {
                NUnit.Framework.Assert.Fail("This test requires permission to access the media library.");
            }
            break;
        }
    }
        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);
            }
        }
Beispiel #4
0
    public static void RequestMediaLibraryPermission(bool assert_granted = false)
    {
        if (MPMediaLibrary.AuthorizationStatus == MPMediaLibraryAuthorizationStatus.NotDetermined)
        {
            if (IgnoreTestThatRequiresSystemPermissions())
            {
                NUnit.Framework.Assert.Ignore("This test would show a dialog to ask for permission to access the media library.");
            }

            MPMediaLibrary.RequestAuthorization((access) =>
            {
                Console.WriteLine("Media library permission: {0}", access);
            });
        }

        switch (MPMediaLibrary.AuthorizationStatus)
        {
        case MPMediaLibraryAuthorizationStatus.Denied:
        case MPMediaLibraryAuthorizationStatus.Restricted:
            if (assert_granted)
            {
                NUnit.Framework.Assert.Fail("This test requires permission to access the media library.");
            }
            break;
        }
    }
Beispiel #5
0
        public bool Authorized()
        {
            if (MPMediaLibrary.AuthorizationStatus != MPMediaLibraryAuthorizationStatus.Authorized)
            {
                MPMediaLibrary.RequestAuthorization(status =>
                {
                    if ((MPMediaLibraryAuthorizationStatus)status != MPMediaLibraryAuthorizationStatus.Authorized)
                    {
                        Messages.Add(
                            "You must authorize the X4Ever to play music. To allow go Settings -> X4Ever then enable Media & Apple Music");
                    }
                });
            }

            return(MPMediaLibrary.AuthorizationStatus == MPMediaLibraryAuthorizationStatus.Authorized);
        }
        Task <PermissionStatus> RequestMediaPermission()
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 3))
            {
                if (MediaPermissionStatus != PermissionStatus.Unknown)
                {
                    return(Task.FromResult(MediaPermissionStatus));
                }

                var tcs = new TaskCompletionSource <PermissionStatus>();

                MPMediaLibrary.RequestAuthorization(status =>
                {
                    switch (status)
                    {
                    case MPMediaLibraryAuthorizationStatus.Authorized:
                        tcs.SetResult(PermissionStatus.Granted);
                        break;

                    case MPMediaLibraryAuthorizationStatus.Denied:
                        tcs.SetResult(PermissionStatus.Denied);
                        break;

                    case MPMediaLibraryAuthorizationStatus.Restricted:
                        tcs.SetResult(PermissionStatus.Restricted);
                        break;

                    default:
                        tcs.SetResult(PermissionStatus.Unknown);
                        break;
                    }
                });

                return(tcs.Task);
            }
            else
            {
                return(Task.FromResult(PermissionStatus.Granted));
            }
        }
        internal static Task <PermissionStatus> RequestMediaLibraryPermission()
        {
            //Opening settings only open in iOS 9.3+
            if (!UIDevice.CurrentDevice.CheckSystemVersion(9, 3))
            {
                return(Task.FromResult(PermissionStatus.Unknown));
            }

            if (MediaLibraryPermissionStatus != PermissionStatus.Unknown)
            {
                return(Task.FromResult(MediaLibraryPermissionStatus));
            }

            var tcs = new TaskCompletionSource <PermissionStatus>();

            MPMediaLibrary.RequestAuthorization(status =>
            {
                switch (status)
                {
                case MPMediaLibraryAuthorizationStatus.Authorized:
                    tcs.TrySetResult(PermissionStatus.Granted);
                    break;

                case MPMediaLibraryAuthorizationStatus.Denied:
                    tcs.TrySetResult(PermissionStatus.Denied);
                    break;

                case MPMediaLibraryAuthorizationStatus.Restricted:
                    tcs.TrySetResult(PermissionStatus.Restricted);
                    break;

                default:
                    tcs.TrySetResult(PermissionStatus.Unknown);
                    break;
                }
            });

            return(tcs.Task);
        }
Beispiel #8
0
        private static bool RequestPermission()
        {
            bool granted = false;

            var permissionStatus = MPMediaLibrary.AuthorizationStatus;

            switch (permissionStatus)
            {
            case MPMediaLibraryAuthorizationStatus.NotDetermined:
                MPMediaLibrary.RequestAuthorization(status =>
                {
                    granted = status == MPMediaLibraryAuthorizationStatus.Authorized;
                });
                return(granted);

                break;

            case MPMediaLibraryAuthorizationStatus.Denied:
                return(false);

                break;

            case MPMediaLibraryAuthorizationStatus.Restricted:
                return(false);

                break;

            case MPMediaLibraryAuthorizationStatus.Authorized:
                return(true);

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }