Check full access for custom keyboard extension

倖福魔咒の 提交于 2019-12-18 12:42:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!