Based on the answer of another question, I've made a file that seems to suit you (I've just translated it from C to Objective-C and removed the printf's; the original link is at the end of the answer).
NSPrivileges.h
#import <Foundation/Foundation.h>
@interface NSPrivileges : NSObject
+(BOOL)hasAdminPrivileges;
@end
NSPrivileges.m
#import "NSPrivileges.h"
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <strings.h>
#include <pwd.h>
#include <grp.h>
@implementation NSPrivileges
+(BOOL)hasAdminPrivileges{
uid_t current_user_id = getuid();
struct passwd *pwentry = getpwuid(current_user_id);
struct group *grentry = getgrgid(getgid());
struct group *admin_group = getgrnam("admin");
while(*admin_group->gr_mem != NULL) {
if (strcmp(pwentry->pw_name, *admin_group->gr_mem) == 0) {
return YES;
}
admin_group->gr_mem++;
}
return NO;
}
@end
Now, you just need to import NSPrivileges.h to the file which needs to know if the user is an admin or not and use the command [NSPrivileges hasAdminPrivileges]
to find out (it will return a BOOL
, so it will be easy to deal with). Hope that helps you.
Here is my reference:
Objective C and OS user type