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;
        }
    }
Beispiel #2
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 #3
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 #6
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();
            }
        }