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.
A:
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: http://stackoverflow.com/questions/823346/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.
nall
2009-09-26 19:42:08
Thanks, that is what I was planning on doing, putting the authorization in the main app delegate. However I am confused as to how I would access it from other classes. Any examples? thanks
macatomy
2009-09-26 23:04:36
Many thanks, will try :-)
macatomy
2009-09-27 01:45:18
Worked. What I ended up doing was creating a separate class that maintains a shared authorization ref.
macatomy
2009-09-28 01:58:38
Great. Glad you got it working.
nall
2009-09-30 07:14:26