I have been trying to get this to work for the past 4 hours. I actually did get it to work about an hour ago, but then came back after a break, played with the code a little, and now it is not working again.
I am trying to implement an optional BOOL method that is declared in PFLoginViewControllerDelegate and it looks like this:
-(BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername:(NSString *)username password:(NSString *)password;
In this Parse tutorial here, it says to paste the following code in to define this BOOL method:
// Sent to the delegate to determine whether the log in request should be submitted to the server.
-(BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername:(NSString *)username password:(NSString *)password {
// Check if both fields are completed
if (username && password && username.length != 0 && password.length != 0) {
return YES; // Begin login process
}
[[[UIAlertView alloc] initWithTitle:@"Missing Information"
message:@"Make sure you fill out all of the information!"
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles:nil] show];
return NO; // Interrupt login process
}
The problem is that I do not get the proper alert view window with a title of "Missing Information" and a body of "Make sure you fill out all of the information!".
I get an alert view window with the title of "Account Error" and a body of "Please double-check your information and try again".
Why is this BOOL method not working properly for me?
Below is the code inside of my View Controller's header file:
#import <Parse/Parse.h>
@interface ParseLoginViewController : PFLogInViewController <PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate>
@end
Below is the code inside of my View Controller's main file:
#import "ParseLoginViewController.h"
#import <Parse/Parse.h>
@interface ParseLoginViewController ()
@end
@implementation ParseLoginViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (![PFUser currentUser]) { // No user logged in
// Create the log in view controller
PFLogInViewController *logInViewController = [[PFLogInViewController alloc] init];
[logInViewController setDelegate:self]; // Set ourselves as the delegate
// Create the sign up view controller
PFSignUpViewController *signUpViewController = [[PFSignUpViewController alloc] init];
[signUpViewController setDelegate:self]; // Set ourselves as the delegate
// Assign our sign up controller to be displayed from the login controller
[logInViewController setSignUpController:signUpViewController];
// Present the log in view controller
[self presentViewController:logInViewController animated:YES completion:NULL];
}
}
// Sent to the delegate to determine whether the log in request should be submitted to the server.
- (BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername:(NSString *)username password:(NSString *)password {
// Check if both fields are completed
if (username && password && username.length != 0 && password.length != 0) {
return YES; // Begin login process
}
[[[UIAlertView alloc] initWithTitle:@"Missing Information"
message:@"Make sure you fill out all of the information!"
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles:nil] show];
return NO; // Interrupt login process
}
@end