rolandleth / LTHPasscodeViewController

iOS 7 style Passcode Lock
MIT License
615 stars 143 forks source link

Delegate Methods not called #105

Closed Oechiih closed 9 years ago

Oechiih commented 9 years ago

For some reason my implementation of the maxNumberOfAllowedFailures and passcodeWasEnteredSuccessfully are never called. It worked a couple of weeks ago...

I'm doing "LTHPasscodeViewControllerDelegate" in the .h file of my LoginViewcontroller and in the ViewDidLoad I'm doing [LTHPasscodeViewController sharedUser].delegate = self;

The Problem might be that "ViewDidLoad" of this ViewController is sometimes not getting called, if the user didn't quit the app. But I don't know where I could put it instead. I tried it in AppDelegate but that didn't work as well.

Any help would be appreciated!

moogle19 commented 9 years ago

Can you post some code of your implementation? Are you using Notifications for the function calls?

Oechiih commented 9 years ago

}

-(void)passcodeWasEnteredSuccessfully{

    if([self loginIsValidForUsername:username andPW:password]){

}else{

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Fehler" message:@"Es ist ein Fehler aufgetreten, Sie müssen sich erneut anmelden." preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){}];

        [alertController addAction:okAction];

        [AppDelegate.contentManager logout];

        UIViewController *loginController = (LoginViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"loginViewController"];
        [self showViewController:loginController sender:self];

        [self presentViewController:alertController animated:YES completion:nil];

    }
}

}

I'm using the function calls and as you can see there is quite a bit of code not shown in the methods above, this is due to safety. Thank you for your insanely quick response!

moogle19 commented 9 years ago

Hmm.. I could not reproduce your problem here. I made a minimal example and it works.

Maybe this minimal code helps :

AppDelegate.h

#import <UIKit/UIKit.h>
#import "LTHPasscodeViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate, LTHPasscodeViewControllerDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

AppDelegate.m

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary     *)launchOptions {
    // Override point for customization after application launch.
    [LTHPasscodeViewController sharedUser].delegate = self;
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    if([LTHPasscodeViewController doesPasscodeExist]) {
        [[LTHPasscodeViewController sharedUser] showLockScreenWithAnimation:YES withLogout:NO andLogoutTitle:nil];
    }
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)passcodeWasEnteredSuccessfully {
    NSLog(@"CORRECT PASSCODE");
}

@end

ViewController.h

#import <UIKit/UIKit.h>
#import "LTHPasscodeViewController.h"

@interface ViewController : UIViewController

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if(![LTHPasscodeViewController doesPasscodeExist]) {
        NSLog(@"Show enabling");
        [[LTHPasscodeViewController sharedUser] showForEnablingPasscodeInViewController:self asModal:NO];
    }
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Oechiih commented 9 years ago

Alright, thank you. Turns out I have to put "[LTHPasscodeViewController sharedUser].delegate = self;" in "aplicationDidBecomeActive". So now it is in fact calling my implementation again but my code isn't doing what it should be. But I can solve this out by myself. Thank you very much for your help! Your Code really helped.