我使用以下代码(在iOS中)在didFinishLaunchingWithOptions
中设置自定义用户代理:
// User agent
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@“CustomAgent", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
这完全适用于所有网络请求。但是,当我创建一个var media = new Media(url); media.play();
时。它在模拟器中尊重它,但在设备上不尊重它。
来自设备:
"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D201 (341099536)”
来自模拟器:
"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D167CustomAgent (4474555984)”
https://github.com/apache/cordova-plugin-media/blob/master/src/ios/CDVSound.m#L393
发布于 2014-07-24 15:54:35
我能够通过在userAgent
中重写CDVViewController
函数来覆盖用户代理。
- (NSString*)userAgent
{
if (_userAgent == nil) {
//NSString* originalUserAgent = [CDVUserAgentUtil originalUserAgent];
_userAgent = [NSString stringWithFormat:@"CustomAgent"];
}
return _userAgent;
}
https://stackoverflow.com/questions/24921751
复制相似问题