屏幕锁定时如何关闭我的iPhone应用程序?

时间:2021-10-29 07:20:17

I'm writing an App that involves authentication on the initial screen, and allows access to sensitive data on later screens. When the iPhone is locked, either with the lock button or through auto-lock, I would like the App to close itself as a security measure. Is there a way I can do this?

我正在编写一个涉及初始屏幕上的身份验证的应用程序,并允许在以后的屏幕*问敏感数据。当iPhone被锁定时,无论是使用锁定按钮还是通过自动锁定,我都希望应用程序将自己关闭作为安全措施。有没有办法可以做到这一点?

4 个解决方案

#1


10  

Your UIApplicationDelegate will receive the

您的UIApplicationDelegate将收到

– applicationWillResignActive:

message when the screen locks, and

屏幕锁定时的消息,和

– applicationDidBecomeActive: 

when it comes back. However, it could also receive these messages in other situations (such as receiving a phone call, the user closes the app on iOS 4.0 and later) and I don't know of a way of distinguishing the reason.

当它回来。但是,它也可以在其他情况下接收这些消息(例如接听电话,用户在iOS 4.0及更高版本上关闭应用程序),我不知道区分原因的方法。

A better user experience in my opinion would be to pop up the authentication again when the app comes back. This way the user won't be confused when the phone unlocks, and the app they had running has mysteriously quit.

我认为更好的用户体验是在应用程序恢复时再次弹出身份验证。这样,当手机解锁时,用户不会感到困惑,并且他们运行的应用程序已经神秘地退出。

#2


6  

To clear up any confusion, I just ran some tests, on a device with iOS 4.3.2:

为了消除任何困惑,我在iOS 4.3.2的设备上运行了一些测试:

When you launch your app, your app gets sent: application:didFinishLaunchingWithOptions: applicationDidBecomeActive:

当您启动应用程序时,您的应用程序将被发送:application:didFinishLaunchingWithOptions:applicationDidBecomeActive:

When you hit the home button, your app gets sent:

当您点击主页按钮时,您的应用会被发送:

applicationWillResignActive:
applicationDidEnterBackground:

When you relaunch that same app later, your app gets sent:

当您稍后重新启动相同的应用时,您的应用会被发送:

applicationWillEnterForeground:
applicationDidBecomeActive:

When you hit the lock button, your app gets sent:

当您点击锁定按钮时,您的应用会被发送:

applicationWillResignActive:

When you unlock, your app gets sent:

解锁后,您的应用会被发送:

applicationDidBecomeActive:

When you get a call, your app gets sent a:

当您接到电话时,您的应用会收到:

applicationWillResignActive:

If you don't answer that call, your app gets sent a:

如果您没有接听该电话,您的应用会收到:

applicationDidBecomeActive:

When you get a call, your app gets sent a:

当您接到电话时,您的应用会收到:

applicationWillResignActive:

If you answer that call, your app gets sent a:

如果您接听该电话,您的应用会收到:

applicationDidEnterBackground:

When you hang up that call, your app gets sent:

挂断电话时,您的应用会被发送:

applicationWillEnterForeground:
applicationDidBecomeActive:

I'd say when you get an applicationWillResignActive: then you should logout, de-authenticate, lock up or discard your confidential info, and when you get an applicationDidBecomeActive: then re-authenticate. That one gets called on launch, return from the background and unlocking of the device.

我会说当你收到一个applicationWillResignActive时:那么你应该注销,取消验证,锁定或丢弃你的机密信息,当你得到applicationDidBecomeActive时:然后重新验证。那个人在启动时被调用,从后台返回并解锁设备。

Also, these two methods may be interesting to you, but they don't really help the specific case that you are interested in:

此外,这两种方法可能对您有意义,但它们并不能真正帮助您感兴趣的特定情况:

- (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application 

- (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application

#3


3  

  1. "Closing your app" goes against Apple guidelines. While some apps actually do this, it is one of the things that can get your app rejected. It was against Apple guidelines before multitasking and is now more important because of multitasking. The user experience is when they come back to the phone and your app after a lock or being in another application, your application should still be running. To "Close your app" would lead the user to believe that you app has crashed and they will likely write reviews to that effect.

    “关闭您的应用程序”违反Apple指南。虽然有些应用实际上是这样做的,但这可能会让您的应用遭到拒绝。在多任务处理之前它违反了Apple的指导原则,现在由于多任务处理而变得更加重要。用户体验是当他们在锁定或进入另一个应用程序后回到手机和您的应用程序时,您的应用程序应该仍在运行。要“关闭你的应用”会让用户相信你的应用已经崩溃,他们可能会写评论。

  2. If your desire is to protect the information in the app when the user goes "away" then You should look into UIApplicationDelegate Protocol Reference. Particualrly applicationDidEnterBackground: (where you should log the user out) and applicationDidBecomeActive: (where you should make the user log back in).

    如果您希望在用户“离开”时保护应用程序中的信息,那么您应该查看UIApplicationDelegate协议参考。 Particually applicationDidEnterBackground :(你应该在哪里记录用户)和applicationDidBecomeActive :(你应该让用户重新登录)。

As a last note, you may want to default to "auto logout" but give the user a settings option to keep them logged in if they wish. Not that hard, and the few who want it can take advantage of the setting.

作为最后一点,您可能希望默认为“自动注销”,但为用户提供一个设置选项,以便他们保持登录状态。没那么难,少数想要它的人可以利用这个设置。

#4


2  

If I remember correctly the App is put to sleep when the phone is locked.

如果我没记错的话,当手机上锁时,应用程序就会进入睡眠状态。

Since the introduction of multitasking Apple changed the behavior so that your App is sent a specific message when unlocked/switched to.

自从多任务Apple的引入改变了行为,以便在解锁/切换时向您的应用程序发送特定消息。

I would suggest to just listen for that thing and then ask for authentication again at this point.

我建议只听那个东西,然后再要求认证。

I dont think you can just quit your App (nor should you), I dont know any App that just kills itself…

我不认为你可以放弃你的应用程序(也不应该),我不知道任何只会杀死自己的应用程序...

Sorry for being not too specific here, but I hope you will now know where to go…

很抱歉这里不太具体,但我希望你现在知道去哪里了...

#1


10  

Your UIApplicationDelegate will receive the

您的UIApplicationDelegate将收到

– applicationWillResignActive:

message when the screen locks, and

屏幕锁定时的消息,和

– applicationDidBecomeActive: 

when it comes back. However, it could also receive these messages in other situations (such as receiving a phone call, the user closes the app on iOS 4.0 and later) and I don't know of a way of distinguishing the reason.

当它回来。但是,它也可以在其他情况下接收这些消息(例如接听电话,用户在iOS 4.0及更高版本上关闭应用程序),我不知道区分原因的方法。

A better user experience in my opinion would be to pop up the authentication again when the app comes back. This way the user won't be confused when the phone unlocks, and the app they had running has mysteriously quit.

我认为更好的用户体验是在应用程序恢复时再次弹出身份验证。这样,当手机解锁时,用户不会感到困惑,并且他们运行的应用程序已经神秘地退出。

#2


6  

To clear up any confusion, I just ran some tests, on a device with iOS 4.3.2:

为了消除任何困惑,我在iOS 4.3.2的设备上运行了一些测试:

When you launch your app, your app gets sent: application:didFinishLaunchingWithOptions: applicationDidBecomeActive:

当您启动应用程序时,您的应用程序将被发送:application:didFinishLaunchingWithOptions:applicationDidBecomeActive:

When you hit the home button, your app gets sent:

当您点击主页按钮时,您的应用会被发送:

applicationWillResignActive:
applicationDidEnterBackground:

When you relaunch that same app later, your app gets sent:

当您稍后重新启动相同的应用时,您的应用会被发送:

applicationWillEnterForeground:
applicationDidBecomeActive:

When you hit the lock button, your app gets sent:

当您点击锁定按钮时,您的应用会被发送:

applicationWillResignActive:

When you unlock, your app gets sent:

解锁后,您的应用会被发送:

applicationDidBecomeActive:

When you get a call, your app gets sent a:

当您接到电话时,您的应用会收到:

applicationWillResignActive:

If you don't answer that call, your app gets sent a:

如果您没有接听该电话,您的应用会收到:

applicationDidBecomeActive:

When you get a call, your app gets sent a:

当您接到电话时,您的应用会收到:

applicationWillResignActive:

If you answer that call, your app gets sent a:

如果您接听该电话,您的应用会收到:

applicationDidEnterBackground:

When you hang up that call, your app gets sent:

挂断电话时,您的应用会被发送:

applicationWillEnterForeground:
applicationDidBecomeActive:

I'd say when you get an applicationWillResignActive: then you should logout, de-authenticate, lock up or discard your confidential info, and when you get an applicationDidBecomeActive: then re-authenticate. That one gets called on launch, return from the background and unlocking of the device.

我会说当你收到一个applicationWillResignActive时:那么你应该注销,取消验证,锁定或丢弃你的机密信息,当你得到applicationDidBecomeActive时:然后重新验证。那个人在启动时被调用,从后台返回并解锁设备。

Also, these two methods may be interesting to you, but they don't really help the specific case that you are interested in:

此外,这两种方法可能对您有意义,但它们并不能真正帮助您感兴趣的特定情况:

- (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application 

- (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application

#3


3  

  1. "Closing your app" goes against Apple guidelines. While some apps actually do this, it is one of the things that can get your app rejected. It was against Apple guidelines before multitasking and is now more important because of multitasking. The user experience is when they come back to the phone and your app after a lock or being in another application, your application should still be running. To "Close your app" would lead the user to believe that you app has crashed and they will likely write reviews to that effect.

    “关闭您的应用程序”违反Apple指南。虽然有些应用实际上是这样做的,但这可能会让您的应用遭到拒绝。在多任务处理之前它违反了Apple的指导原则,现在由于多任务处理而变得更加重要。用户体验是当他们在锁定或进入另一个应用程序后回到手机和您的应用程序时,您的应用程序应该仍在运行。要“关闭你的应用”会让用户相信你的应用已经崩溃,他们可能会写评论。

  2. If your desire is to protect the information in the app when the user goes "away" then You should look into UIApplicationDelegate Protocol Reference. Particualrly applicationDidEnterBackground: (where you should log the user out) and applicationDidBecomeActive: (where you should make the user log back in).

    如果您希望在用户“离开”时保护应用程序中的信息,那么您应该查看UIApplicationDelegate协议参考。 Particually applicationDidEnterBackground :(你应该在哪里记录用户)和applicationDidBecomeActive :(你应该让用户重新登录)。

As a last note, you may want to default to "auto logout" but give the user a settings option to keep them logged in if they wish. Not that hard, and the few who want it can take advantage of the setting.

作为最后一点,您可能希望默认为“自动注销”,但为用户提供一个设置选项,以便他们保持登录状态。没那么难,少数想要它的人可以利用这个设置。

#4


2  

If I remember correctly the App is put to sleep when the phone is locked.

如果我没记错的话,当手机上锁时,应用程序就会进入睡眠状态。

Since the introduction of multitasking Apple changed the behavior so that your App is sent a specific message when unlocked/switched to.

自从多任务Apple的引入改变了行为,以便在解锁/切换时向您的应用程序发送特定消息。

I would suggest to just listen for that thing and then ask for authentication again at this point.

我建议只听那个东西,然后再要求认证。

I dont think you can just quit your App (nor should you), I dont know any App that just kills itself…

我不认为你可以放弃你的应用程序(也不应该),我不知道任何只会杀死自己的应用程序...

Sorry for being not too specific here, but I hope you will now know where to go…

很抱歉这里不太具体,但我希望你现在知道去哪里了...