YH_HTTPRequestSerializer.m 1.62 KB
//
//  YH_HttpRequestSerializer.m
//  YH_Mall
//
//  Created by jhsonzhi on 15/8/24.
//  Copyright (c) 2015年 YOHO. All rights reserved.
//

#import "YH_HttpRequestSerializer.h"
#import <OpenUDID.h>
#import <JTSHardwareInfo.h>
#import "UtilsMacros.h"
#import <YH_Analytics.h>
#import <AdSupport/AdSupport.h>

#define kScreenScale                ([UIScreen instancesRespondToSelector:@selector(scale)]?[[UIScreen mainScreen] scale]:(1.0f))

@implementation YH_HttpRequestSerializer

-(instancetype)init
{
    if (self = [super init]) {
        [self setValue:[self yh_getYohoUserAgent] forHTTPHeaderField:@"User-Agent"];
    }
    
    return self;
}

- (NSString *)yh_getYohoUserAgent
{
    NSString * udidString = [OpenUDID value];
    if (!udidString) {
        udidString = @"";
    }
    
    NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
    long longTime = (long)time;
    NSString *userAgent = [NSString stringWithFormat:@"%@/%@(Model/%@;OS/iOS%@;Scale/%0.2f;Channel/%@;Resolution/%ld*%ld;Udid/%@;sid/%@;ts/%ld;uid/%@;ifa/%@)",
                           
                           [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleNameKey],
                           [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey],
                           [JTSHardwareInfo hardwareDisplayName],[[UIDevice currentDevice] systemVersion],kScreenScale, @"2919",(long)kScreenWidth,(long)kScreenHeight, udidString,[[YH_Analytics sharedInstance] session],longTime, @"",[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]];
    return userAgent;
}

@end