nickoneill / PermissionScope

Intelligent iOS permissions UI and unified API
MIT License
4.85k stars 507 forks source link

Get list of added permissions and remove when needed? #157

Closed basememara closed 8 years ago

basememara commented 8 years ago

Great plugin, it works beautifully! Thanks for sharing!!

I noticed that configuredPermissions is not public, but I need to get a list of added permissions. The reason is because location services is optional in my app. If they choose to use GPS in my app, then my added permissions are fine.

However, if they decide not to use GPS in my app anymore and turn it off, I need to remove the location services permission from PermissionScope otherwise it will bug them for nothing.

Is there a way to dynamically view and remove added permissions at runtime? My idea was to make my PermissionScope variable null and re-instatialize and dynamically add the permissions back based on some conditions, but I still can't get a list of added permissions. permissionStatuses seems to give me all status regardless of what permissions were added. Am I understanding this correctly?

nickoneill commented 8 years ago

I wouldn't attempt to remove the permissions based on what users have already accepted, but you should definitely reconfigure PermissionScope to only ask for the permissions that your app wants. If the user turns off a GPS feature in your app, simply don't configure PermissionScope with the location permission next time.

basememara commented 8 years ago

The PermissionScope instance is already configured for the user based on their settings (with or without GPS), but if the user changes their settings, then the PermissionScope instance is stuck on the old permissions.

I am calling show in viewWillAppear to ensure the user always provides the right access for the user. That's when I'd like to re-configure PermissionScope based on the user's latest settings or leave it alone if the settings hasn't changed. I'm willing to kill the PermissionScope in viewWillAppear and recreate it with the latest permissions, but I'm having trouble figuring out when I should kill it instead of brute-force wiping the instance every time.

nickoneill commented 8 years ago

I don't think there's anything wrong with recreating the PermissionScope object on viewWillAppear in your case. The whole thing is very light and the impact of recreating it is probably negligible.

basememara commented 8 years ago

Cool thanks for the confirmation. I found one better than brute-force, in my settings screen I'm running this when the GPS setting is changed/saved by the user:

if let controller = self.tabBarController?.viewControllers?[0] as? TimesController {
  controller.permissionScope = nil
}

Then in the viewWillAppear in my TimesController, I'm recreating the PermissionScope instance if it is nil and dynamically adding the permissions back based on the latest user settings from NSUserDefaults. Works great!

Thanks again for the help and amazing library!!