Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Featurerequest: allow mutiple permissions to be checked like in previous versions #143

Open
csteeg opened this issue Jun 6, 2019 · 2 comments

Comments

@csteeg
Copy link

csteeg commented Jun 6, 2019

In 5.0 it's not possible to ask for multiple permissions at once AND use the new linking stuff.
Please introduce a way to ask multiple permissions.
I created an implementation in my iOS and Android project like this:

Android:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Plugin.Permissions;
using Plugin.Permissions.Abstractions;

namespace XXX.Droid.Permissions
{
    public class MultiPermissionRequestor : IMultiPermissionRequestor
    {
        private static FieldInfo fieldAccessor = typeof(BasePermission).GetField("permission", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance);

        public async Task<Dictionary<Type, PermissionStatus>> RequestPermissionsAsync(params BasePermission[] permissions)
        {
            Dictionary<Permission, Type> mappings = permissions.ToDictionary(p => (Permission)fieldAccessor.GetValue(p), p => p.GetType());

            Dictionary<Permission, PermissionStatus> status = await CrossPermissions.Current.RequestPermissionsAsync(mappings.Select(kv => kv.Key).ToArray()).ConfigureAwait(false);

            return status.ToDictionary(st => mappings[st.Key], st => st.Value);
        }
    }
}

iOS:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Plugin.Permissions;
using Plugin.Permissions.Abstractions;

namespace XXX.iOS.Permissions
{
    public class MultiPermissionRequestor : IMultiPermissionRequestor
    {
        public async Task<Dictionary<Type, PermissionStatus>> RequestPermissionsAsync(params BasePermission[] permissions)
        {
            Dictionary<Type, PermissionStatus> result = new Dictionary<Type, PermissionStatus>();
            foreach (BasePermission p in permissions)
            {
                result.Add(p.GetType(), await p.RequestPermissionAsync().ConfigureAwait(false));
            }

            return result;
        }
    }
}

This code also makes clear that an extra feature is requested from my side : make BasePermission.Permission a public property instead of a protected field :)

@jamesmontemagno
Copy link
Owner

I am not sure how that will work with the linker. My assumption is that it will run into the same issue as before.

@csteeg
Copy link
Author

csteeg commented Jun 14, 2019

@jamesmontemagno why would it, what am I missing? it would just be the same as calling permission.RequestPermissionAsync() multiple times in your own code on iOS? But on android it will be able to submit all requests at once, so you get the 1 out 2, 2 out of 2 permission dialog there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants