gpt4 book ai didi

ios - 如何检测 iOS 中特定 View Controller 的空闲时间/非事件时间?

转载 作者:行者123 更新时间:2023-12-01 18:34:05 25 4
gpt4 key购买 nike

由于我对移动应用程序开发和堆栈溢出非常陌生,因此我需要进行个人培训以检测应用程序特定 View Controller 中的空闲时间。我正在 WKWebview 中加载 Web URL。因此,如果用户在此屏幕上花费大约 3 分钟的空闲时间,我的应用程序应该注销并进入主屏幕。经历了几个 SO 问题,但所有这些问题都为整个应用程序实现了一个共同的空闲时间,但就我而言,我只想要这个特定的 View Controller 。这是我在 WKWebview 中显示 Web URL 的 View Controller 代码:

#import "WebViewController.h"
#import <WebKit/WebKit.h>

@interface WebViewController ()<WKNavigationDelegate,WKUIDelegate>{
WKWebView *_wkViewer;
}

@end

@implementation WebViewController

- (void)viewDidLoad {
[super viewDidLoad];
_wkViewer = [[WKWebView alloc] initWithFrame:CGRectMake(0,[UIApplication sharedApplication].statusBarFrame.size.height + 50, self.view.frame.size.width, self.view.frame.size.height -([UIApplication sharedApplication].statusBarFrame.size.height+70))];
[_wkViewer setAutoresizingMask: UIViewAutoresizingFlexibleWidth];
NSURL *url = [NSURL URLWithString: self.productURL];
NSURLRequest *urlReq = [NSURLRequest requestWithURL:url
[_wkViewer loadRequest:urlReq];
[self.view addSubview:_wkViewer];
}

-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, self.view.frame.size.width, 50)];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], NSForegroundColorAttributeName,
[UIFont fontWithName:@"Arial" size:20.0], NSFontAttributeName,nil]];
[navBar setAutoresizingMask: UIViewAutoresizingFlexibleWidth];
[UINavigationBar appearance].barTintColor = [UIColor whiteColor];
[self.view addSubview: navBar];
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(backClicked)]
UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:_titleName];
navigItem.leftBarButtonItem = cancelItem;
navBar.items = [NSArray arrayWithObjects: navigItem,nil];
[UIBarButtonItem appearance].tintColor = [UIColor whiteColor];
}

- (void)backClicked {
[self dismissViewControllerAnimated:YES completion:nil];
}

@end

最佳答案

您可以使用 NSTimer 并在该特定 View Controller 上注册 TapGesture,当 NSTimer 方法调用 3 分钟后,您可以将用户重定向到您想要的任何地方。

关于ios - 如何检测 iOS 中特定 View Controller 的空闲时间/非事件时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63894745/

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