我的iOS程序宣传自己的HTTP用户代理是什么? [英] What HTTP User-Agent does my iOS program advertise itself as?

查看:105
本文介绍了我的iOS程序宣传自己的HTTP用户代理是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的播客编写了一个应用程序 Otaku no Podcast 。在应用程序的各个部分,我使用 NSURLConnection (获取RSS提要), UIWebView (显示网站内容), AVPlayer (从我们的CDN播放MP3音频文件)和 MPMoviePlayerViewController (播放CDN上的视频文件)。现在,由于所有这些都会产生某种类型的HTTP请求,我假设他们会使用标准的iPhone User-agent字符串来宣传自己。 (如果我的假设不正确,请告诉我)这意味着,基于阅读我的日志文件,我无法通过普通的旧手机Safari告诉我哪些访问者,而不是使用我的应用。



有没有办法将用户代理更改为我自己的代理?我在SO上找到了这个问题描述如何使用 NSURL 执行此操作,但我找不到任何有关上述任何类别的信息。

解决方案

您的原始假设部分不正确 - 自定义用户代理字符串用于您应用的NSURLRequests。在我的测试中,字符串是

 < product-name> /< build-number> CFNetwork / 548.0.3 Darwin / 11.2.0 

然而,来自UIWebView的一些请求使用此用户代理string

  Mozilla / 5.0(iPhone模拟器; CPU iPhone OS 5_0,如Mac OS X)AppleWebKit / 534.46(KHTML,与Gecko一样)移动/ 9A334 

可能是因为网站可以优化设备的HTML,即使它不是MobileSafari。 / p>

I've written an app for my podcast, Otaku no Podcast. In various parts of the app, I use NSURLConnection (fetch RSS feeds), UIWebView (display website content), AVPlayer (play MP3 audio files off our CDN), and MPMoviePlayerViewController (play video files off our CDN). Now, since all of these make HTTP requests of some sort, I'm assuming that they will advertise themselves with the standard iPhone User-agent string. (if my assumption is incorrect please let me know) This means that, based on reading my log files, I have no way of telling which of my visitors is coming in via plain old mobile Safari, vs. using my app.

Is there a way of changing the User-Agent to one of my own? I found this question on SO that describes how to do this with NSURL but I can't find any information about any of the above classes that I am using.

解决方案

Your original assumption is partly incorrect- A custom User-agent string is used for NSURLRequests from your app. In my testing, the string is

<product-name>/<build-number> CFNetwork/548.0.3 Darwin/11.2.0

However, some requests from UIWebView use this user-agent string

Mozilla/5.0 (iPhone Simulator; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A334

presumably so that websites can optimise their HTML for the device even if it's not MobileSafari.

这篇关于我的iOS程序宣传自己的HTTP用户代理是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆