如何在iOS 5中更改UIWebView的用户代理?
到目前为止我做了什么: 使用委托回调,拦截NSURLRequest,创建一个新的url请求并将其用户代理设置为我想要的任何内容,然后下载数据并使用"loadData:MIMEType:...重新加载UIWebView" ".
问题: 这会导致无限递归,我加载数据,调用代理返回,实习生调用委托....
这是委托方法:
- (BOOL)webView:(UIWebView *)aWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
dispatch_async(kBgQueue, ^{
NSURLResponse *response = nil;
NSMutableURLRequest *newRequest = [NSMutableURLRequest requestWithURL:[request URL]];
NSDictionary *headers = [NSDictionary dictionaryWithObject:
@"custom_test_agent" forKey:@"User-Agent"];
[newRequest setAllHTTPHeaderFields:headers];
[self setCurrentReqest:newRequest];
NSData *data = [NSURLConnection sendSynchronousRequest:newRequest
returningResponse:&response
error:nil];
dispatch_sync(dispatch_get_main_queue(), ^{
[webView loadData:data
MIMEType:[response MIMEType]
textEncodingName:[response textEncodingName]
baseURL:[request URL]];
});
});
return YES;
}
Run Code Online (Sandbox Code Playgroud) 当我在iOS应用中登录Gmail时,我收到以下错误(屏幕截图),并且未显示登录字段.我们正在WKWebView中加载登录屏幕.
我已经读过谷歌正在弃用OAuth的网页视图,并将在2017年4月20日阻止请求.正如Google开发人员博客中所见:https: //developers.googleblog.com/2016/08/modernizing-oauth-interactions-in -native-apps.html
这是否意味着我已经需要使用或是否有其他可行的解决方案?在我需要更新之前,我想我还有更多时间.
我正在构建一个网络浏览器,最近我在尝试使用我在网站上的Google帐户登录时遇到了错误.
这很奇怪,因为我检查了我的应用程序和Safari的用户代理,它们都是相同的.
有什么建议?
UPDATE
WKWebView嵌套在自定义UIViews树的3层深处.
这是初始化代码:
_webView = [[WKWebView alloc] init];
_webView.allowsBackForwardNavigationGestures = NO;
_webView.allowsLinkPreview = NO;
_webView.navigationDelegate = self;
_webView.UIDelegate = self;
_webView.frame = CGRectMake(0.0, 0.0, self.contentView.frame.size.width, self.contentView.frame.size.height);
[self.contentView addSubview:_webView];
Run Code Online (Sandbox Code Playgroud) 关于此主题还有其他几个问题/答案,但他们没有将Firebase与Ionic一起使用.我刚刚切换到新的Ionic View,现在,我的应用程序在旧的Ionic View中工作,而新的Ionic View给出了这个众所周知的错误:
403错误 - 这是一个错误.错误:disallowed_useragent不允许其用户代理向Google发出OAuth授权请求,因为它被归类为嵌入式用户代理(也称为Web视图).等等等等等等
在我的代码中,我注入Firebase AuthProvider并使用angularfire2进行连接,它看起来像
private getProvider(from: string): AuthProvider {
switch (from) {
case 'twitter': return new firebase.auth.TwitterAuthProvider();
case 'facebook': return new firebase.auth.FacebookAuthProvider();
case 'github': return new firebase.auth.GithubAuthProvider();
case 'google': return new firebase.auth.GoogleAuthProvider();
}
}
signIn(from: string) {
this.afAuth.auth.signInWithPopup(this.getProvider(from))
. . .
Run Code Online (Sandbox Code Playgroud)
再次,这在浏览器或旧的Ionic中很有用,但不适用于新的Ionic View.我确实有一个相当大的库与一般OAuth连接,但我认为使用Firebase的一个重要原因是我们不再需要使用这些库并自己管理用户.
有没有办法通过Ionic在iOS/Android应用上进行Firebase身份验证?
firebase firebase-authentication angularfire2 ionic3 angular
我是移动应用程序开发的新手,我正在开发一个ios应用程序.其中我使用谷歌驱动器从谷歌帐户将文档文件存入我的应用程序.我做了那个任务并且运行正常.但是现在当我尝试进行身份验证时它现在无法正常工作显示403错误:我的应用程序中的disallowed_useragent.关于这个问题,我搜索了一些令人困惑的东西,我读了这个 堆栈溢出问题 ,我发现谷歌驱动器已经更新,现在我不知道我是否想要重做我的任务或者必须更新任务才能完成登录,请任何人建议我对此
谢谢你的到来
ios ×4
google-oauth ×3
android ×1
angular ×1
angularfire2 ×1
cocoa-touch ×1
cordova ×1
firebase ×1
ionic3 ×1
oauth ×1
objective-c ×1
uiwebview ×1
uri-scheme ×1
user-agent ×1
wkwebview ×1