【问题标题】:Changing User-Agent in phonegap app works in simulator but not on device在 phonegap 应用程序中更改用户代理在模拟器中有效,但在设备上无效
【发布时间】:2013-11-07 05:09:43
【问题描述】:

我有一个基于 IOS 平台构建的 PhoneGap 3.0 应用。

我在AppDelegate.mdidFinishLaunchingWithOptions 方法中添加了以下两行,以尝试欺骗特定的用户代理(在查看了许多 SO 问题之后):

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"my custom user agent", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

当我在 IOS 模拟器中运行应用程序并检查 navigator.userAgent 时,我得到了预期的“我的自定义用户代理”作为输出。

当我进行远程 phonegap 构建时,在我的 iPhone 上运行应用程序并检查 navigator.userAgent,我得到的是标准 iPhone 用户代理,而不是我的自定义用户代理。

为什么我在模拟器和我的设备上从 navigator.userAgent 得到不同的输出?

相关的 SO 问题:

Change Phonegap User Agent

Detect between a mobile browser or a PhoneGap application

【问题讨论】:

    标签: ios iphone objective-c cordova


    【解决方案1】:

    为什么我从模拟器和我的设备上的 navigator.userAgent 得到不同的输出?

    当我们进行远程 phonegap 构建时,我们实际上是在压缩项目的资产并上传它们,因此我们对项目的 www 目录之外的文件所做的任何更改都会被忽略。

    phonegap 构建服务正在自己构建并创建自己的AppDelegate.m,而无需更改编辑用户代理,这解释了为什么我们在设备上看不到自定义用户代理,而我们在模拟器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-25
      • 1970-01-01
      相关资源
      最近更新 更多