开发者

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/CPLockController

I 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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜