当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Accessing KeychainItems in action extension

问题描述:

I'm building an action extension for my iOS app. However, I'm having some real difficulties with handling user data. In my app I'm storing the user's username and password like this:

 KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"testapp" accessGroup:nil];

[keychainItem setObject:[self.txtUsername text] forKey:(__bridge id)(kSecAttrAccount)];

[keychainItem setObject:[self.txtPassword text] forKey:(__bridge id)(kSecValueData)];

NSString *valueToSave = @"Remembermebycredentials";

[[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:@"RememberMe"];

[[NSUserDefaults standardUserDefaults] synchronize];

How can I access this from my action extension? I tried retrieving it with the same identifier and creating a shared container, but that didn't work...

网友答案:

You can not access the saved data from your app until you make access group.You need to configure application for access group it is not directly available to your extension as your extension is different process.

I recommend to follow a tutorial and WWDC Session

Creating App Extensions for iOS and OS X, Part 1

Creating App Extensions for iOS and OS X, Part 2

分享给朋友:
您可能感兴趣的文章:
随机阅读: