0
我試圖實現代碼爲我的應用程序創建帳戶。到目前爲止,我認爲我很好地理解從文本字段獲取數據是否將其存儲在覈心數據數據庫中,但我不確定如何將用戶在應用程序的鑰匙串中創建的引腳存儲起來。我跟着this tutorial創建了一個名爲的賬戶,我認爲這是AccountBase的一個子類。該Account.m文件有一個方法聲明:爲應用程序創建ios帳戶的核心數據+鑰匙串
- (void)setPassword:(NSString*)aPassword
現在,我敢肯定,這是我要用來設置爲我的應用「腳」的方法。我不知道如何應用於我的ViewControllerCreate.m文件。整個方法是這樣的:
- (void)setPassword:(NSString*)aPassword
{
if (self.username) [KeychainHelper setPassword:aPassword forKey:self.username];
}
到目前爲止,我有我的ViewControllerCreate.m文件驗證碼:
- (IBAction)createAccount:(id)sender {
// hide keyboard when login button is pressed
[_createUserTextField resignFirstResponder];
// check if create textfields are empty - WRONG
[self checkTextFieldCharLength];
// check if boolean is true/false
if([self checkTextFieldEmpty] == TRUE) // empty text fields
{
NSLog(@"Please fill in text fields");
}
else {
NSLog(@"Thanks for filling out the text fields.");
// Core Data - retrieve values from text fields and store in database.
NSManagedObject *newAccount;
newAccount = [NSEntityDescription insertNewObjectForEntityForName:@"Account" inManagedObjectContext:_managedObjectContext];
[newAccount setValue:_createUserTextField forKey:@"username"];
[newAccount setValue:_createEmailTextField forKey:@"email"];
[newAccount setValue:_createPhoneNumber forKey:@"phoneNumber"];
// TODO store pin in keychain
_createUserTextField.text = @"";
_createEmailTextField.text = @"";
_createPhoneNumber.text = @"";
NSError *error;
[_managedObjectContext save:&error];
[_createAccountSuccess setHidden:NO];
NSLog(@"Succefully created account.");
}
}
任何人都知道我怎麼會去存儲輸入引腳到鑰匙扣當按下「創建」按鈕時。