react-native - Webview userAgent 在反应 natvie 中不起作用
问题描述
<WebView source={{html:'...'}} userAgent={DeviceInfo.getUserAgent()}></WebView>
我用来WebView
向服务器发送请求并设置userAgent
. 但是发现user-agent
服务器收到的是okhttp/3.6.0
. 那么有什么问题userAgent
呢?
解决方案
您发送了收到的数据DeviceInfo.getUserAgent()
,我建议将您的自定义数据添加userAgent
到您打算在服务器上传递的属性中。例如在 WebView 中设置自定义数据,它应该在 Android 版本中按预期工作。
<WebView
source={ {uri: this.props.url} }
userAgent="demo-react-native-app"
/>
最终它不适用于 iOS 版本,这里 AppDelegate.m 文件中的几行代码需要它的支持。
NSString *newAgent = @"demo-react-native-app";
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:newAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
推荐阅读
- ios - -layoutAttributesForDecorationViewOfKind 没有 UICollectionViewLayoutAttributes 实例:路径上的 shadowDecorationView
- c# - 当 %20 结尾时,Asp.net 分页
- vue.js - 从 vuejs2 迁移到 vuejs3 的 CSS 转换问题
- reactjs - 如何设置 MUI DatePicker 的占位符文本?
- python - 根据一个参考计算多个 GPS 位置之间的距离
- python-3.x - 从字典中获取所有值与列表的交集
- vb.net - 如何在 Visual Basic .NET 中对有符号整数进行零扩展
- delphi - 针对 MS Graph API 的 Indy TIdHttp put 命令的内容范围问题
- flutter - 展开条子时如何为标题添加对比度?
- python - numpy:打印数组强制科学记数法