Saving authorization object

Now I have an application that performs some actions using AuthorizationExecuteWithPrivileges. The problem is that it must ask for a password for each operation. Is there a way in which I could authenticate as soon as the application starts so that it does not request authorization later, and then release the authorization object when it is released. I need to access the authorization object through several classes, so is there a way to do this? I saw how it is implemented in other applications, but I'm not sure how to do it myself.

+3
source share
1 answer

Can you request authorization in the application delgate applicationDidFinishLaunching and release in applicationWillTerminate?

Then you can save the general authorization authorizer in the application deletion and access it from various classes that require it.

You can access it through:

[[NSApp delegate] sharedAuthenticationRef]; // Mac Desktop

or

[[[UIApplication sharedApplication] delegate] sharedAuthenticationRef]; // iPhone

It is assumed that you created the accessory sharedAuthenticationRefin your delet.

This question is also relevant: Best practice for application delegation

Another approach would be to create a singleton class in which a singleton instance receives authorization in the initializer and frees it in dealloc.

+1
source

Source: https://habr.com/ru/post/1718606/


All Articles