我正在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
答案 0 :(得分:0)
我可以通过覆盖userAgent
中的CDVViewController
功能来覆盖用户代理:
- (NSString*)userAgent
{
if (_userAgent == nil) {
//NSString* originalUserAgent = [CDVUserAgentUtil originalUserAgent];
_userAgent = [NSString stringWithFormat:@"CustomAgent"];
}
return _userAgent;
}