我正在尝试在我的iOS应用中实现KeyChain共享,以便在不同的iOS应用程序之间共享密码。
我正在使用库UICKeyChainStore
来实现此目的。
AppDelegate.m(这可行)
self.keychainStore = [UICKeyChainStore keyChainStoreWithService:@"PasswordService" accessGroup:@"group_name"];
self.keychainStore[@"password"] = @"abcd1234";
NSLog(@"%@", self.keychainStore[@"password"]);
在我的ViewController的ViewDidLoad方法中,相同的代码只是在控制台中打印(null)。
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.keychainStore[@"p2"] = @"1234";
NSLog(@"%@", appDelegate.keychainStore[@"p2"]);
当我深入挖掘库时,抛出的错误信息是:
错误Domain = com.kishikawakatsumi.uickeychainstore Code = -34018 “发生了安全错误。”的UserInfo = 0x174e76540 {NSLocalizedDescription =发生了安全错误。}