如何在应用程序启动时显示锁定屏幕?

发布于 2024-10-30 07:45:11 字数 285 浏览 5 评论 0原文

我正在尝试在启动应用程序时显示锁定屏幕。
我正在尝试使用这里的代码 -> https://github.com/jazzychad/CPLockController

我尝试在viewDidLoad函数中触发锁屏,但模态屏幕从未启动。我还尝试触发应用程序委托 didFinishLaunchingWithOptions 函数中的锁定,但未成功。

有人可以帮我吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画离情绘悲伤 2024-11-06 07:45:11

您可能还想在 applicationWillEnterForeground 上显示锁定屏幕,以便快速切换应用程序。

You may also want to present your lock screen on applicationWillEnterForeground for the sake of fast app switching.

雨后咖啡店 2024-11-06 07:45:11

这是一个愚蠢的问题。我没有完全理解代表们的想法。

我正在为偶然发现这个问题的人们提供答案。

首先确保将 #import "CPLockController.h" 添加到应用程序委托标头中,然后将 CPLockControllerDelegate 添加到应用程序委托标头中。

@interface SampleAppAppDelegate : NSObject <UIApplicationDelegate, CPLockControllerDelegate> {

然后在 applicationDidFinishLaunching 函数中,使用视图控制器启动模式。

- (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];
}

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文