ユーザー名とパスワードを識別するためにサーバーURLデータベース接続を呼び出しました。私はNSURLを使用しました。間違ったユーザー名とパスワードを入力すると、NSLog に接続が正常に表示されます。正しいユーザー名とパスワードを入力すると、接続が正常に表示されます。ユーザー名とパスワードUITextFieldに何も入力しない場合は、ログインボタンをクリックすると、接続が正常に表示されます。正しいユーザー名とパスワードのみを取得する必要があります
コード:
-(void)login:(id)sender{
NSString *uname=usrname.text;
NSString *pword=password.text;
NSURL *theURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://myserver.net/projects/mobile/database_connection.php?name=%@&password=%@",uname, pword]]; //Here you place your URL Link
NSLog(@"url is %@",theURL);
NSURLRequest *req = [NSURLRequest requestWithURL:theURL];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:req delegate:self];
if (connection) {
NSLog(@"connection successful");
}
else {
NSLog(@"Failed");
}
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
//NSLog(@"Did Receive Data %@", data);
[receiveData appendData:data];
}
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[receiveData setLength:0];
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"recieved data lenght is %d", [receiveData length]);
}
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
{
NSLog(@"%@" , error);
}
// Implement TextField delegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
-(void)touchesBegan :(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
}