模拟 iPhone 上的触摸

发布于 2025-01-04 13:22:33 字数 143 浏览 1 评论 0原文

我试图模拟 UIWebView 上的触摸,如何以编程方式在某个位置触发触摸事件? (x 和 y 坐标) 只调用touchesBegan?

理想情况下,我想在没有任何 javascript hack 的情况下做到这一点,因为将来它可能不是 uiwebview

Im trying to simulate a touch on as UIWebView, how can I programmatically fire a touch event at a certain location? (x and y coordinates)
Just call touchesBegan?

Ideally I'd like to do it without any javascript hack because in the future it may not be a uiwebview

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

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

发布评论

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

评论(5

南渊 2025-01-11 13:22:33

在 iPhone 上合成触摸事件并不容易:你必须使用未公开的 API,因此你很有可能在 iOS 的每次更新中崩溃并被 Apple 拒绝。

这里一个链接,演示如何合成触摸iPhone 上的事件:

这是 StackOverflow 上的另一个问题:如何将触摸事件发送到 iPhone 操作系统?

It's not easy to synthesize a touch event on the iPhone: you have to use undisclosed API, so you have a high probability of breaking on every update of the iOS and getting rejecting from Apple.

Here's a link that demonstrates how to synthesize a touch event on the iPhone:

Here's another question on StackOverflow: How to send a touch event to iPhone OS?

め七分饶幸 2025-01-11 13:22:33

这里值得指出的是 KIF 框架。它旨在在模拟器中运行,但部分代码是在代码中模拟触摸事件。幸运的话,这将是一个很好的起点。

https://github.com/square/KIF

具体请查看 stepToTapViewWithAccessibilityLabelKIFTestStep.m 和行

[view tapAtPoint:tappablePointInElement];

It's worth pointing out the KIF framework here. It's intended to run in the simulator but part of the code is simulating touch evens in code. with luck, this will be a good starting point.

https://github.com/square/KIF

Specifically, look at stepToTapViewWithAccessibilityLabel in KIFTestStep.m and the line

[view tapAtPoint:tappablePointInElement];
假装不在乎 2025-01-11 13:22:33

你需要做的是首先创建你想要的事件,然后通过“紫色端口”将它们发送到SpringBoard,例如。马赫港。要使它们在系统范围内使用,您必须通过端口将它们转发到每个应用程序。这意味着您需要实际执行窗口管理器所做的事情,并查看哪个应用程序处于活动状态、屏幕锁定等。

有大量可用的私有框架 API(IOSurface、GraphicServices、SpringBoardServices 等)可以帮助您获取所需信息。你需要。

您必须在运行时使用 dlopen() 之类的工具加载这些私有框架。

从 iOS 6.1.4(当前的 ATM)开始,无需越狱,这是 100% 可能的,但您将加载苹果 AppStore 不允许的私有框架;)

What you need to do is first create the events you want, and then send them to SpringBoard over the "purple port" eg. mach port. To make them system wide you must forward them to each application over the port. That means you need to actually do what the windowmanager does and looking at which app is active, screen locked, etc.

There are a hand full of private framework APIs that work (IOSurface, GraphicServices, SpringBoardServices, etc.) to get you the pieces you need.

You will have to load these private frameworks at runtime using something like dlopen().

This is 100% possible without jailbreak as of iOS 6.1.4 (current ATM), but you will be loading private frameworks which is not allowed by apple for AppStore ;)

骷髅 2025-01-11 13:22:33

这是可能的。正如您所提到的,使用 GSEvents 并将它们发送到您尝试控制/模拟的应用程序的紫色命名端口。当然,您需要 KennyTM 的 GSEvent.h 来完成此任务。
我已经为 iOS 4.3 做到了这一点,只需更改 Kenny 拥有的一些值(如 kGSHandInfoTypeTouchDown),但现在我尝试为 iOS 5 做到这一点,但到目前为止还不起作用。

编辑:它现在适用于 iOS 5.1。

It is possible. Exactly how you mentioned, using GSEvents and sending them to the purple named port of the aplication you are trying to control/simulate. Of course you need KennyTM's GSEvent.h to accomplish this.
I've done this for iOS 4.3, just by changing some of the values that Kenny had (like kGSHandInfoTypeTouchDown), but now I'm trying to do it for iOS 5 and it's not working, till now.

EDIT: It is now working for iOS 5.1.

醉态萌生 2025-01-11 13:22:33

如果不越狱,就没有真正的方法将手势识别器连接到整个系统的所有视图。首先,您在后台运行的应用程序无法执行此代码。

Without jailbreaking there is no real way to hook a gesture recognizer into all views of the entire system. First off, your app running in the background doesn't have the ability of executing this code.

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