我需要获取所有单词,这些单词在UIWebView的屏幕上可见.我的UIWebView有html内容.
有人可以帮帮我.
当你事先知道请求需要它时,我已经看到许多 问题(并回答)如何提供凭证.
当我加载请求身份验证质询的站点时(使用HTTP 401响应),我UIWebViewDelegate只收到以下回调:webView:shouldStartLoadWithRequest:navigationType:有时webViewDidStartLoad:(webViewDidStartLoad:如果我直接导航到该站点,似乎会被调用,如果我',它似乎不会被调用m重定向那里).
通过覆盖-[NSObject respondsToSelector:],UIWebViewDelegate接收一些调用uiWebView:resource:canAuthenticateAgainstProtectionSpace:forDataSource:和uiWebView:resource:didReceiveAuthenticationChallenge:fromDataSource:,这可能是有用的,但当然这些是私有API,可能会让我的应用程序被拒绝.
我用嵌入式UIWebViews 测试了一些不同的主流应用程序.到目前为止,只有Chrome正确处理这些身份验证挑战.我甚至已经设置了自己的服务器并验证了Chrome只有POST一次.Twitter和Tweetbot失败只是永远显示加载屏幕,就像我的.
除了使用第二个推测之外,还有另一种(可能是非常hacky)方法来检测这些身份验证挑战NSURLConnection吗?如果我提出POST请求,那将POST是一切,这是不好的.
这个简单的代码
var iframe = document.createElement('iframe');
document.documentElement.appendChild(iframe);
通过注入UIWebView stringByEvaluatingJavascriptFromString
产生的调用UIWebViewDelegate shouldStartLoadWithRequest与about:blank.有趣的是,这仍然适用mainDocumentURL于注射时存在的文件.对我而言,这意味着我不能随时注入这样的代码 - 重新进入shouldStartLoadWithRequest可以显着地打破很多东西.我可以拒绝所有about:blank的请求(返回NO从shouldStart...从互联网络)和代码段做cluelessly,但它几乎没有一个系统的解决方案.
任何想法为什么UIWebView会有这种混乱和无用的行为?
我正在开发一个iPhone项目,我必须从Instagram上拍摄图像.我在其开发者网站上提到了以下API:
当我在我的网址中点击此网址时UIWebview出现以下错误:
错误域= WebKitErrorDomain代码= 102"帧加载中断"
但是,当我在设备浏览器中点击相同的URL时,它可以工作.但它将URL修改为:
我还试图将这个修改过的URL放在我的代码中.然后它工作,并要求我登录.但是当我登录时,我收到此错误.
{
"code": 400,
"error_type": "OAuthException",
"error_message": "You must include a valid client_id, response_type, and redirect_uri parameters"
}
Run Code Online (Sandbox Code Playgroud)
我最近创建了一个客户端ID并检查了所有参数.所以我不确定问题是什么.我用Google搜索,发现UIWebView不允许这样做.所以我把它didFinishLaunching放在我的AppDelegate班上:
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
Run Code Online (Sandbox Code Playgroud)
但这也行不通.请告知有关此问题的任何解决方案.
我正在测试一个包含许多不同文档类型的UIWebview - .xlsx,.jpg等等 - 它打开了大部分文档就好了.我不时会打开一个本地文件,这条消息会出现在Web视图中:
Unable to Read Document
An error occurred while reading the document
Run Code Online (Sandbox Code Playgroud)
我不关心"为什么"这个错误发生 - 例如,当我向UIWebView提供垃圾文件(故意)时,它就会发生.问题是我无法弄清楚如何检测"何时"发生这种情况.它不会触发web视图:didFailLoadWithError,它不会触发NSException(通过@try&@catch),当我在检查文件webViewDidFinishLoad,webView.request.HTTPBody为空.
任何人都知道如何检测UIWebView何时无法显示内容?
我有一个UIWebView工作正常.代表正在工作.当我打开一个URL,事件shouldStartLoadWithRequest和webViewDidFinishLoad被解雇.
但是,例如,当我点击Google搜索结果时,只会shouldStartLoadWithRequest被触发,并且webViewDidFinishLoad永远不会被调用.
这会导致问题,因为如果我打开"loading ..."指示器shouldStartLoadWithRequest,在这些情况下,即使页面正确加载后指示器仍然保持不变.
知道为什么会这样吗?
我需要在加载webview中的任何url时检查响应状态代码.现在我们可以考虑在web视图中加载的任何Web应用程序.所以我需要跟踪具有该webview的每个请求并相应地检查响应代码.为了找到响应代码,我需要在uiwebview的委托方法"shouldStartLoadWithrequest"中使用NSUrlConnection.有点像这样 -
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType{
NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:self];
if (conn == nil) {
NSLog(@"cannot create connection");
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
和NSURLConnectionDelegate一样 -
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSLog(@"connection:didReceiveResponse");
[self log:@"received response."];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
int status = [httpResponse statusCode];
NSLog(@"http status code: %d", status);
if (status == 200) {
NSLog(@"Response OK");
}
else {
NSLog(@"Response is not OK");
}
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSLog(@"connection:didReceiveData");
}
- …Run Code Online (Sandbox Code Playgroud) iphone uiwebview ios uiwebviewdelegate nsurlconnectiondelegate
我有问题,当youtube播放器将全屏进入或在iOS 8中退出全屏时因为这些通知被删除UIMoviePlayerControllerDidEnterFullscreenNotification而且UIMoviePlayerControllerWillExitFullscreenNotification此版本的操作系统版本.
由于我的应用程序项目仅设置为纵向模式,因此在播放时视频不会旋转为横向模式,这在您的设备上观看视频时实际上不太友好.
通常,当视频以全屏模式进入时,用户希望以纵向模式或横向模式观看视频.
这就是我为iOS 7做的方式,它在iOS 8中运行得很完美.
首先,我将AppDelegate.m在我AppDelegate.h调用 videoIsInFullscreen 和函数的boolean属性中设置此函数,
// this in the AppDelegate.h
@property (nonatomic) BOOL videoIsInFullscreen;
// This in my AppDelegate.m to allow landscape mode when the boolean property is set to yes/true.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if(self.videoIsInFullscreen == YES)
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的ViewController.m第一个,我会#import "AppDelegate.h"在这之后,我将在我的viewDidLoad方法中添加一些通知..
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerStarted) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil]; …Run Code Online (Sandbox Code Playgroud) 我无法从UIWebView响应中获取标头,因为响应显然没有被缓存。有解决方法吗?我已经从试图代码在这里。
混合原生的iOS我的应用程序使用视图控制器和UIWebView的。当我开始一个UIWebView会议上,我与写从哪里令牌从API登录救了我的钥匙链令牌的身份验证的cookie。
如果用户导航到Web视图中的另一个页面,则cookie似乎不正确。我的目标是从每个响应中获取身份验证cookie,并将其保存为服务器的身份验证令牌随每个请求的变化而变化。然后,我要添加的令牌回到了新的要求。
下面的代码总是返回零。我想从头令牌一个auth。
func webViewDidFinishLoad(webView: UIWebView) {
if let request = webView.request {
if let resp = NSURLCache.sharedURLCache().cachedResponseForRequest(request) {
if let response = resp.response as? NSHTTPURLResponse {
print(response.allHeaderFields)
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个网页,将由iOS和Android应用程序使用webview调用。
是否可以在网页中执行此操作,或者是否由打开网络视图的应用程序进行管理?这怎么可能呢?
我读过一些有关UIWebViewDelegate的内容,但我不确定它是否是正确的解决方案。
谢谢
uiwebview ×9
ios ×6
iphone ×4
objective-c ×3
javascript ×2
android ×1
dom ×1
iframe ×1
instagram ×1
ios5 ×1
swift3 ×1
webview ×1
youtube-api ×1