iPhone 捕获任何应用程序交互
我只是想知道是否有任何方法可以捕获用户与应用程序的交互。
我问的原因是,当用户与应用程序交互时,我会更新数据库中的日期。如果他们的约会时间超过 10 分钟,其他用户就会将他们视为离线,直到他们回来并与程序交互。
有人对我如何捕获任何用户交互来更新此字段有任何想法吗?
谢谢
它是一个导航应用程序。所以即使我可以向导航控制器添加一个处理程序来说明页面何时更改,这可能会做???
Im just wondering if there is any method of catching any user interaction with the application.
The reason i ask is that when a user interacts with the app i update a date in the db. if they date is older than 10 minutes they are seen as offline by other users until they comeback and interact with the program.
Does anybody have any ideas on how i could catch any user interaction to update this field?
Thanks
p.s. it is a navigation app. so even if i can add a handler to the navigation controller to say when a page is changed that might do???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最方便的方法可能是子类化 UIApplication 并重写
sendAction:to:from:forEvent:
方法。您还需要在 Info.plist 文件中添加一个名为“NSPrincipalClass”的键,其中包含一个包含子类名称的字符串值,该字符串值将 UIKit 告知您的子类,而不是 UIApplication。MyApplication.m:
Info.plist:
The most convenient way would probably be to subclass UIApplication and override the
sendAction:to:from:forEvent:
method. You will also need to add a key to your Info.plist file called “NSPrincipalClass” with a string value containing the name of your subclass, which tells UIKit to your subclass in place of UIApplication.MyApplication.m:
Info.plist:
如果您所说的交互指的是“触摸”,那么您可以通过在 NavigationController 中的每个 UIViewController 上放置一个 UIView(如果没有全局的 UIView)来轻松实现这一点,该 UIViewController 负责注册触摸,保存当前的触摸日期到更高级别的控制器(甚至 AppDelegate 也可能工作)。然后,该控制器可以将日期与前一个日期进行比较(您必须存储它),如果时间差超过您的阈值,您可以通过向正确的对象发送消息来触发您的操作。
这里是Apple关于如何捕获触摸的指南(您需要重写
touchesBegan:WithEvent:
方法来获取第一次触摸)If by interaction you mean 'touches' then you can easily do that by putting a UIView (if do not have a global one on top of the others) on each UIViewController in your NavigationController that has the duty of registering a touch, saving the current date to an higher level controller (even the AppDelegate might work). Then this controller can compare the date to the previous one ( you have to store it) and if the time difference overcomes your threshold you can fire your action by messaging the proper object.
Here is a guide from Apple on how to catch the touches (you will need to overrid the
touchesBegan:WithEvent:
method to get the first touch)