我正在使用Parse SDK。我想从Parse API表中获取数据,并希望将过滤器设置为用户名和密码。我怎样才能做到这一点。下面给出的是在NSURLSession的帮助下完成的示例代码,并希望使用Parse SDK类将其转换为代码。
try (Reader inputReader = new InputStreamReader(clientSocket.getInputStream(), StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(inputReader)) {
System.out.println(read.readLine());
System.out.println(read.readLine());
}
答案 0 :(得分:0)
请在此处查看Parse Integration以向现有项目添加解析。
请尝试以下代码:
//如果您使用的是自定义表,那么
PFQuery *query = [PFQuery queryWithClassName:@"TableName"];
[query whereKey:@"username" equalTo:@"pass your username here"];
[query whereKey:@"password" equalTo:@"pass your password here"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if(!error){
if(objects.count>0)
// Found User
}
}];
或者您正在使用USER表,然后尝试以下代码
[PFUser logInWithUsernameInBackground:username password:password
block:^(PFUser *user, NSError *error) {
if (user) {
// Found User
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login Error" message:@"Credentials provided were incorrect. Please try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}];
答案 1 :(得分:0)
假设您已经在代码上集成了Parse SDK。 使用以下方法。
-(void)validateLoginWithUsername:(NSString *)usernam withPassword:(NSString *)pasword
{
[PFUser logInWithUsernameInBackground:usernam password:pasword
block:^(PFUser *user, NSError *error) {
if (user) {
// Do stuff after successful login.
} else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Invalid Login" message:@"Please Check the username and password entered" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
}];
}
答案 2 :(得分:0)
您可以使用以下代码使用解析API检索记录... 您可以使用PFQuery类的
来应用过滤器PFQuery *query = [PFQuery queryWithClassName:@"UserDetails"];
__block int totalNumberOfEntries = 0;
[query orderByDescending:@"createdAt"];
[query whereKey:@"UserName" containsString:@"anand"];
[query whereKey:@"Password" containsString:@"1234"];
[query countObjectsInBackgroundWithBlock:^(int number1, NSError *error)
{
if (!error)
{
NSLog(@"------- number-- %d",number1);
NSLog(@"------- number-- %d",[profileArray count]);
if (totalNumberOfEntries > [profileArray count])
{
NSLog(@"Retrieving data");
//query.skip=[NSNumber numberWithInt:2300];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d records.", objects.count);
int j=[profileArray count];
if([objects count]>j)
{
[profileArray addObjectsFromArray:objects];
NSLog(@"array count is %d",[profileArray count]);
NSLog(@"array is %@",profileArray);
}
}
else
{
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
} else
{
// The request failed, we'll keep the Data count?
number1 = [profileArray count];
}
}];
希望它对你有用......!