如何从iOS应用程序Web视图中识别浏览?

时间:2015-11-30 13:46:57

标签: php ios iphone apache

我有一个网站和原生iOS应用程序,所以当有人从iOS手机浏览网站版本时,我会添加一个横幅来下载应用程序。在移动应用程序内部,一些功能打开内部webview,显示应用程序内的网站。我想避免在本机应用程序的Web视图中显示横幅。

我目前正在认识iPhone:

// Query all StateA and StateB objects from the database and
// process them as soon as they arrive.
service.GetStatesA().ContinueWith((t) => DoSomething(t.Result));
service.GetStatesB().ContinueWith((t) => DoSomething(t.Result));

// Some other code

// Actually access the API such that the data is queried and the Tasks completed.
service.SendRequests();

除了向本机应用程序的所有请求添加内容之外,有没有办法通过任何/我的应用程序的Web视图来识别浏览?

2 个答案:

答案 0 :(得分:0)

我建议您查看Mobile-Detect库。

通过它,您可以检测到正在加载页面的设备的类型,操作系统等等。

使用这样的库可以解决你脑子里的很多问题..

答案 1 :(得分:0)

对于您的iOS应用,您可以修改用户代理以包含有关您应用的内容。

然后在JS或服务器端检查该用户代理。

像...一样的东西。

let userAgent = UIWebView().stringByEvaluatingJavaScriptFromString("navigator.userAgent")! + " Custom-Agent"
NSUserDefaults.standardUserDefaults().registerDefaults(["UserAgent" : userAgent])