Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retaining an authorization object

Right now I have my application executing some things using AuthorizationExecuteWithPrivileges. The problem is that it needs to ask for the password for every operation. Is there any way I could have it authenticate as soon as the app starts so that it won't ask for authorization later, and then release the authorization object when its dealloced. I need to access the authorization object across multiple classes, so is there any way to do this? I've seen this implemented in other apps, I'm unsure of how to do it myself though.

like image 997
indragie Avatar asked Feb 26 '26 15:02

indragie


1 Answers

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

You could then keep the shared AuthorizationRef in the application delegate, and access it from the various classes that require it.

You could access it via:

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

or

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

This assumes you've created the sharedAuthenticationRef accessor in your delegate.

This question is also pertinent: Best Application Delegate Practice

Another approach would be to create a singleton class where the singleton instance acquires the authorization in the initializer and releases it in the dealloc.

like image 168
nall Avatar answered Mar 01 '26 07:03

nall