gpt4 book ai didi

iphone - 根据用户事件注销

转载 作者:可可西里 更新时间:2023-11-01 06:23:50 26 4
gpt4 key购买 nike

我一直在寻找这个答案,但找不到解决方案。任何人都可以告诉我我们如何计算自用户与应用程序进行任何交互以来的后台时间。在少数网站中,如果您一段时间不与网页交互,您将被注销。我正在寻找此功能。

非常感谢您抽出时间。谢谢

最佳答案

我认为您可以通过 UIApplication 自定义子类捕获事件。您可以在那里重新启动您的空闲计时器,而不会弄乱您的所有代码。方法如下:

制作你自己的 UIApplication 子类:

@interface MyUIApplication : UIApplication {
NSTimer *idleTimer;
}
@property(nonatomic,retain) NSTimer *idleTimer;

在你的 main() 中

int retVal = UIApplicationMain(argc, argv, @"MyUIApplication", nil);

在您的应用程序 subclass.m 中,覆盖 sendEvent: 和 sendAction:。请参阅 Apple 文档 here :

- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
[self. idleTimer invalidate];
self. idleTimer = [NSTimer scheduledTimerWithTimeInterval:kIDLE_TIME target:self selector:@selector(logout:) userInfo:nil repeats:NO];}

... 发送操作相同。您也可以将注销逻辑放在此类中:

- (void)logout:(NSTimer *)timer {
// do logout
}

当应用程序退出时,您仍然应该在您的应用程序委托(delegate)中注销(并使计时器无效):

- (void)applicationWillResignActive:(UIApplication *)application {
[application logout:nil];
}

关于iphone - 根据用户事件注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6920052/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com