我是Objective-c的新手。 我无法理解怎么做,当你启动程序时自动插入保存在NSTextFiel和NSSecureTextField中的姓氏。 我保存了用户名和密码:
- (void)saveLoginPass {
if ([checkBox state]==NSOnState) {
[SSKeychain setPassword:self.passwordField.stringValue forService:@"ERClient" account:self.loginField.stringValue];
NSLog(@"Login/pass save");
}
else if([checkBox state]==NSOffState){
NSLog(@"Don't save login/pass");
}
}
和
[manager POST:URLString parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject){
if ([operation.responseString rangeOfString:@"mainBody"].location == NSNotFound) {
alertFild.stringValue=@"Login or pass false";
NSLog(@"Login or pass false");
NSLog(@"responseObject: %@", responseObject);
NSLog(@"operation.responseString: %@",operation.responseString);
NSLog(@"operation.response: %@",operation.response);
} else {
browserWindowController = [[ERBrowserWindowController alloc] initWithWindowNibName:@"ERBrowserWindowController"];
[browserWindowController showWindow:self];
[browserWindowController addDefaultTabs];
[self saveLoginPass];
[loginWindow close];
NSLog(@"Аuthorized");
}
}
我在Keychain中检查了成功存储的数据。 加载程序时如何使实现插入最终的登录名和密码?
答案 0 :(得分:0)
我想你可以用标准的方式检索用户名和密码。
NSDictionary *credentials = [SSKeychain accountsForService:@"ERClient"].firstObject;
if (!credentials) {
return; // leave fields empty
}
NSString *accountName = credentialsDictionary[kSSKeychainAccountKey];
NSString *password = [SSKeychain passwordForService:@"ERClient" account:accountName];
// populate fields
}