gpt4 book ai didi

iOS 代码无法检测通过 UI Webview 加载的 URL

转载 作者:行者123 更新时间:2023-11-29 02:23:30 25 4
gpt4 key购买 nike

我的 iOS 应用程序是一个巨大的 Web View ,我们使用监听器脚本来检测用户何时注销。

if([currentURL isEqualToString:@"http://app.edupal.co/logout/index"])
{
EPAppDelegate *delegate = (EPAppDelegate*)[[UIApplication sharedApplication] delegate];
NSString *strURL = [NSString stringWithFormat:@"http://app.edupal.co/logout/index?deviceId=%@&os=ios", delegate.token];
NSLog(@"strURL:%@" , strURL);

NSURL *tulaUrl = [NSURL URLWithString:strURL];
NSURLRequest *eduPalReq = [NSURLRequest requestWithURL:tulaUrl];
[self.edupalWebView loadRequest:eduPalReq];

[timer invalidate];
timer = nil;
}

监听器将检测 Web View 是否变为 http://app.edupal.co/logout/index 并将其替换为 http://app.edupal.co/logout/index?deviceId={device token}&os=ios

计时器组件每 0.1 秒运行一次,但由于某种原因根本无法检测到 URL。

这是日志中的证据。

timer2http://app.edupal.co/student/account/?

deviceId=9ce97c872173f8927f878484c911774fec8df83f5bf8e6ec564df7a3deb6785a&os=ios
2015-01-08 06:33:21.810 EduPal[1210:371457] timer2 9ce97c872173f8927f878484c911774fec8df83f5bf8e6ec564df7a3deb6785a
2015-01-08 06:33:21.914 EduPal[1210:371457] timer2:::::
2015-01-08 06:33:21.915 EduPal[1210:371457] timer2http://app.edupal.co/student/account/?deviceId=9ce97c872173f8927f878484c911774fec8df83f5bf8e6ec564df7a3deb6785a&os=ios
2015-01-08 06:33:21.915 EduPal[1210:371457] timer2 9ce97c872173f8927f878484c911774fec8df83f5bf8e6ec564df7a3deb6785a
2015-01-08 06:33:21.975 EduPal[1210:371457] LoadingGif Stopped:::
2015-01-08 06:33:22.008 EduPal[1210:371457] timer2:::::
**// user clicks logout button here and /logout/index page is never loaded //**

2015-01-08 06:33:22.009 EduPal[1210:371457] timer2http://app.edupal.co/login/auth
2015-01-08 06:33:22.010 EduPal[1210:371457] timer2 9ce97c872173f8927f878484c911774fec8df83f5bf8e6ec564df7a3deb6785a
2015-01-08 06:33:22.109 EduPal[1210:371457] timer2:::::
2015-01-08 06:33:22.110 EduPal[1210:371457] timer2http://app.edupal.co/login/auth
2015-01-08 06:33:22.111 EduPal[1210:371457] timer2 9ce97c872173f8927f878484c911774fec8df83f5bf8e6ec564df7a3deb6785a
2015-01-08 06:33:22.209 EduPal[1210:371457] timer2:::::
2015-01-08 06:33:22.210 EduPal[1210:371457] timer2http://app.edupal.co/login/auth

最佳答案

不要使用计时器,也不要将当前 URL 与任何内容进行比较。这整个方法是错误的。你不应该那样投票!相反,只需在 WebView 上设置一个委托(delegate)。每当用户尝试导航到新页面时都会调用该委托(delegate)。因此,您将能够以这种方式检测到导航到注销页面。

关于iOS 代码无法检测通过 UI Webview 加载的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27832218/

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