49 lines
1.1 KiB
Plaintext
49 lines
1.1 KiB
Plaintext
#import "KeyChainPlugin.h"
|
||
#import "UICKeyChainStore.h"
|
||
|
||
NSString *_keyForUUID = @"B2_IOS_USER_GUID";
|
||
|
||
@implementation KeyChainPlugin
|
||
|
||
extern "C" {
|
||
char* getKeyChainUser();
|
||
void setKeyChainUser(const char* uuid);
|
||
void deleteKeyChainUser();
|
||
}
|
||
|
||
char* getKeyChainUser()
|
||
{
|
||
NSString *userUUID = [UICKeyChainStore stringForKey:_keyForUUID];
|
||
|
||
if (userUUID == nil || [userUUID isEqualToString:@""]) {
|
||
NSLog(@"No user information");
|
||
userUUID = @"";
|
||
}
|
||
|
||
return makeStringCopy([userUUID UTF8String]);
|
||
}
|
||
|
||
void setKeyChainUser(const char* uuid)
|
||
{
|
||
NSString *nsUUID = [NSString stringWithCString: uuid encoding:NSUTF8StringEncoding];
|
||
|
||
[UICKeyChainStore setString:nsUUID forKey:_keyForUUID];
|
||
}
|
||
|
||
void deleteKeyChainUser()
|
||
{
|
||
[UICKeyChainStore removeItemForKey:_keyForUUID];
|
||
}
|
||
|
||
char* makeStringCopy(const char* str)
|
||
{
|
||
if (str == NULL) {
|
||
return NULL;
|
||
}
|
||
|
||
char* res = (char*)malloc(strlen(str) + 1);
|
||
strcpy(res, str);
|
||
return res;
|
||
}
|
||
|
||
@end |