没有设置user_agent的情况下,Ti会自动进行设置,设置文件在
/Users/xxx/Library/Application Support/Titanium/mobilesdk/osx/2.0.1.GA2/iphone/Classes下的Tiapp.mm文件,搜索useragent找到相关代码:
- (NSString*)userAgent
{
if (userAgent==nil)
{
UIDevice *currentDevice = [UIDevice currentDevice];
NSString *currentLocaleIdentifier = [[NSLocale currentLocale] localeIdentifier];
NSString *currentDeviceInfo = [NSString stringWithFormat:@"%@/%@; %@; %@;",[currentDevice model],[currentDevice systemVersion],[currentDevice systemName],currentLocaleIdentifier];
NSString *kTitaniumUserAgentPrefix = [NSString stringWithFormat:@"%s%s%s %s%s","Appc","eler","ator","Tita","nium"];
userAgent = [[NSString stringWithFormat:@"%@/%s (%@)",kTitaniumUserAgentPrefix,TI_VERSION_STR,currentDeviceInfo] retain];
}
return userAgent;
}
可见userAgent基本包含了以上信息。
但是
NSString *kTitaniumUserAgentPrefix = [NSString stringWithFormat:@"%s%s%s %s%s","Appc","eler","ator","Tita","nium"];
这一句是我们不想发送出去的,这包含了Appcelerator Titanium的信息。 所以我替换为:NSString *kTitaniumUserAgentPrefix = [NSString stringWithFormat:@"%s","App"];
这样我们就修改了Titanium的userAgent配置文件。 也保证我们的app不发送多余的信息出去。
PS: 关于user agent的介绍见wikipedia: http://en.wikipedia.org/wiki/User_agent