我想驗證用戶輸入的用戶名和密碼是否與sqlite數據庫一致。如果用戶名和密碼存在於數據庫中,用戶不需要登錄。但是如果他的用戶名和密碼不匹配,他需要登錄。我已經添加了下面的代碼在我的appdelegate第一:從數據庫中檢索數據時出現問題
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
databaseName [email protected]"journeymapper.db3";
NSArray *documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentsPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
[self checkAndCreateDatabase];
}
-(void)checkAndCreateDatabase{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:databasePath];
if (success)
return;
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:databaseName];
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
[fileManager release];
}
-(void)readLoginFromDatabase{
sqlite3 *database;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK){
const char *sqlStatement = "Select Username,Password from UserInformation";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK){
NSString *aUserName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aPassword = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
最初如果數據庫存在。如果不是我創造one.Then我從數據庫中讀取我檢查。
然後在我的登錄控制器的登錄動作我已經添加以下代碼:
-(IBAction)login:(id)sender{
journey = (JourneyAppDelegate *)[[UIApplication sharedApplication]delegate];
if ([mUserName.text isEqualToString:@"shardulprabhu"] && [mPassword.text isEqualToString:@"password"]) {
[journey readLoginFromDatabase];
NSLog(@"journey read");
}
else{
[self signUp];
}
}
此代碼檢查名爲myusername和密碼equaltostring指定的數據庫中,如果它等於它應該從數據庫中讀取。否則它應該註冊。但是當我運行我的應用程序我的應用程序加載時,當我輸入用戶名和密碼,然後單擊登錄按鈕應用程序崩潰。 我有上登錄操作的警告JourneyAppDelegate可能不響應,readLoginFromDatabase
可能是什麼問題
感謝
。可妳告訴控制檯屏幕上的錯誤可能會不響應警告不會產生任何問題 – 2011-04-01 12:40:06