samhuri.net-ios/Pods/OMGHTTPURLRQ/OMGUserAgent.m
2014-10-18 14:19:51 -07:00

19 lines
934 B
Objective-C

#import <Foundation/Foundation.h>
#import "OMGUserAgent.h"
NSString *OMGUserAgent() {
static NSString *ua;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
id info = [NSBundle mainBundle].infoDictionary;
id name = info[@"CFBundleDisplayName"] ?: info[(__bridge NSString *)kCFBundleIdentifierKey];
id vers = (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: info[(__bridge NSString *)kCFBundleVersionKey];
#ifdef UIKIT_EXTERN
float scale = ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [UIScreen mainScreen].scale : 1.0f);
ua = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", name, vers, [UIDevice currentDevice].model, [UIDevice currentDevice].systemVersion, scale];
#else
ua = [NSString stringWithFormat:@"%@/%@", name, vers];
#endif
});
return ua;
}