在UIWebView(iOS)中聆听事件 [英] Listening for events in a UIWebView (iOS)

查看:139
本文介绍了在UIWebView(iOS)中聆听事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我在iOS应用程序中的UIWebView中打开的网页中收听一个事件(特别是一个按钮点击)。我知道在其他语言中有一些方法可以将事件监听器附加到某些Web调用中,但是我还没有找到在Objective-C中执行此操作的方法。我还没有找到任何人在线说谁不能完成,所以我决定我应该问。我在文档中看到可以使用Javascript来进行Objective-C调用,但是我无法控制我想要监视的网页。所以我需要一个解决方案,让我可以在Objective-C中完全听取这个事件。

I'm trying to listen for an event (specifically a button click) from a webpage I have opened in a UIWebView in my iOS app. I know that in other languages there are ways to attach event listeners to certain web calls, but I haven't yet found a way to do it in Objective-C. I also haven't found anyone online who says it can't be done, so I decided I should ask. I saw in the documentation that you can make Objective-C calls from Javascript, but I do not have control of the webpage I am wanting to monitor. So I need a solution that allows me to listen for this event entirely in Objective-C.

编辑:如果细节有帮助,我试图让用户做Facebook上的墙柱。我正在UIWebview(http://www.facebook.com/sharer/sharer.php?u=)中加载Facebook sharer页面,并希望监控用户何时点击共享链接,以便关闭网页视图

If specifics would help, I am trying to allow the user to make a wallpost on Facebook. I am loading the Facebook sharer page in a UIWebview (http://www.facebook.com/sharer/sharer.php?u=) and wanting to monitor when the user clicks "Share Link" so that I can close the web view.

谢谢大家的时间!

推荐答案

使用UIWebViewDelegate:

You can use the UIWebViewDelegate:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

UIWebViewNavigationType值为:

The UIWebViewNavigationType values are :

enum {
  UIWebViewNavigationTypeLinkClicked,
  UIWebViewNavigationTypeFormSubmitted,
  UIWebViewNavigationTypeBackForward,
  UIWebViewNavigationTypeReload,
  UIWebViewNavigationTypeFormResubmitted,
  UIWebViewNavigationTypeOther
};typedef NSUInteger UIWebViewNavigationType;

可以检查一下,然后看NSURLRequest获取有关

Can check this and then look at the NSURLRequest to get info about that

这篇关于在UIWebView(iOS)中聆听事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆