How to display lock screen on app start up?
I'm trying to display a lock screen on the launch of my app.
I'm trying to use the code here -> https://github.com开发者_运维技巧/jazzychad/CPLockControllerI tried to trigger the lock screen in the viewDidLoad function, but the modal screen never launched. I also unsuccessfully tried to trigger the lock in the application delegate didFinishLaunchingWithOptions function.
Can anyone help me out?
You may also want to present your lock screen on applicationWillEnterForeground for the sake of fast app switching.
This was a silly question. I wasn't fully understanding delegates.
I'm providing the answer for people that happen to stumble upon this.
First be sure to add the #import "CPLockController.h" and then the CPLockControllerDelegate to the application delegate header.
@interface SampleAppAppDelegate : NSObject <UIApplicationDelegate, CPLockControllerDelegate> {
Then in the applicationDidFinishLaunching function, launch the modal using the view controller.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
CPLockController *lockController = [[CPLockController alloc]initWithStyle:CPLockControllerTypeAuth];
lockController.passcode = @"1234";
lockController.delegate = self;
lockController.title = @"Passcode is 1234";
lockController.modalPresentationStyle = UIModalPresentationFormSheet;
[viewController presentModalViewController:lockController animated:NO];
[window makeKeyAndVisible];
}
精彩评论