问题
I need to check full access for custom keyboard extension. I found this link.
How to check the "Allow Full Access" is enabled in iOS 8?
It say we can check App group. I have app group called "group.TTT.TGroup". It share access between main app and custom keyboard.
Then, I check like this. Problem is that I always have access to that (always has array or error = null). Is it because I am sharing same data? But, if my app use another app group and extension use other app group, I can't definitely access to that. May I know how to do?
NSFileManager* fileManager = [NSFileManager defaultManager];
NSString *path = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.TTT.TGroup"].path;
NSError *error;
NSArray *arr = [fileManager contentsOfDirectoryAtPath:path error:&error];
NSLog(@" arr is %@",arr);
if (arr == nil || !arr) //can check error also
accessOn = NO;
else accessOn = YES;
回答1:
You can try reading a value from the shared NSUserDefaults
- if the value is null, then allowFullAccess is off
Or you can try reading files from the shared file system using containerURLForSecurityApplicationGroupIdentifier
回答2:
+(bool)fullAccessAccessible{
NSUserDefaults *myDefaults = [[NSUserDefaults alloc]
initWithSuiteName:APP_GROUP_NAME];
NSString* test_key = @"extension test full access";
[myDefaults setBool:TRUE forKey:test_key];
BOOL res = [myDefaults boolForKey:test_key];
return res == TRUE;//set and get compare
}
来源:https://stackoverflow.com/questions/26072140/check-full-access-for-custom-keyboard-extension