Showing posts with label Forgot Password Alert Popup. Show all posts
Showing posts with label Forgot Password Alert Popup. Show all posts

Tuesday, December 15, 2015

How to create Forgot Password Default Alert Popup for all iOS Apps



//Declare in .h file
NSString * forgotPasswordAlertText;

//Forgot Password button Actions Methods
- (IBAction)forgotPasswordButtonTapped:(id)sender{

    UIAlertView * altView = [[UIAlertView alloc] initWithTitle:@"Forgot Password?"message:@"Please enter your email address." delegate:self cancelButtonTitle:@“Cancel"otherButtonTitles:@"OK", nil];
    altView.tag = 101;
    [altView setAlertViewStyle:UIAlertViewStylePlainTextInput];
    [altView textFieldAtIndex:0].placeholder = @"Email Address";
    [altView textFieldAtIndex:0].keyboardType = UIKeyboardTypeEmailAddress;
    [altView textFieldAtIndex:0].returnKeyType = UIReturnKeyDone;
    [altView textFieldAtIndex:0].text = forgotPasswordAlertText;
    [altView show];
}

#pragma mark Alert view Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (alertView.tag) {
        //101 tag for forgot password
        case 101:
            switch (buttonIndex) {
                case 1:
                    forgotPasswordAlertText = [alertView textFieldAtIndex:0].text;
                    if (![self validateEmail:forgotPasswordAlertText]){
                        showAlertOkAction( @"Check Email", @"Please Enter Proper Username");
                    }else{
                        //call web service method from here
                        forgotPasswordAlertText = @"";
                    }
                    break;
                    
                default:
                    break;
            }
            break;
        //102 tag for reopen forgot password alert
        case 102:
            [self forgotPasswordButtonTapped:nil];
            
        default:
            break;
    }
}

//For Email Validation

-(BOOL)validateEmail:(NSString*)email{
    
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    BOOL isValid = [emailTest evaluateWithObject:email];
    
    return isValid;
}


//Declare in Constant File


#define showAlertOkAction(messageT,title) UIAlertView *alert=[[UIAlertView alloc] initWithTitle:messageT message:title delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil, nil];[alert show];alert.tag = 102;alert.delegate = self;