I'm new on objc/Cocoa and I never use C before.
I've a problem to get previously defined C struct data…
Here's my code :
AppController.h
#import <Cocoa/Cocoa.h> @interface AppController : NSObject { AuthorizationRef authRef; AuthorizationRights authRights; AuthorizationFlags authFlags; } - (IBAction)toggleAuthentification:(id)sender; @end AppController.m
#import "AppController.h" @implementation AppController - (id)init { if (![super init]) return nil; AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authRef); AuthorizationItem rightItems[1] = {{"com.myname.myapp.adminRights", 0, NULL, 0}}; authRights.count = 1; authRights.items = rightItems; authFlags = kAuthorizationFlagDefaults | kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize; return self; } - (IBAction)toggleAuthentification:(id)sender { NSLog(@"%d", AuthorizationCopyRights(authRef, &authRights, kAuthorizationEmptyEnvironment, authFlags ^ kAuthorizationFlagInteractionAllowed, NULL)); } @end When I click on a button in my app that call toggleAuthentification:, I get error code -60008 (errAuthorizationInternal).
In the debugger I can see authRights.count = 1, that correct, but authRights.items do not correspond in any way to data defined in init.
I try many different way but I don't find solution.
Please, anyone can explain why it doesn't work like I would it work and how to resolve my problem.
Bil