天天看点

获取设备型号,app版本,提交时间,网络类型等信息

#pragma mark 获取服务器端记录的数据

-( void )getAppInfo

{

     content  =  _opinionTV . text ;

     infoSource  =  InfoSource ; // 信息来源

     tel  =  _phoneTV . text ;

     qq  =  _qqTV . text ;

     mail  =  _mailTV . text ;

     // 提交时间

     NSDate  *now = [ NSDate   date ];

     NSCalendar  *calendar = [ NSCalendar   currentCalendar ];

     NSUInteger  unitFlags =  NSYearCalendarUnit  |  NSMonthCalendarUnit  |  NSDayCalendarUnit  |  NSHourCalendarUnit  |  NSMinuteCalendarUnit ;

     NSDateComponents  *dateComponents = [calendar  components :unitFlags  fromDate :now];

     int  year = [dateComponents  year ];

     int  month = [dateComponents  month ];

     int  day = [dateComponents  day ];

     int  hour = [dateComponents  hour ];

     int  minute = [dateComponents  minute ];

     NSLog ( @"year is: %d" , year);

     NSLog ( @"month is: %d" , month);

     NSLog ( @"day is: %d" , day);

     NSLog ( @"hour is: %d" , hour);

     NSLog ( @"minute is: %d" , minute);

     // 用户 IMEI 号 (null)

     sc  =  _CTServerConnectionCreate ( kCFAllocatorDefault ,  callback ,  NULL );

     _CTServerConnectionCopyMobileIdentity (& result ,  sc , & imei );

     NSLog  ( @"IMEI is %@" ,  imei );

     // 用 OpenUDID 替代 IMEI

     openUDID  = [ HXY_OpenUDID   value ];//导入HXY_OpenUDID文件

     // 连接网络类型

     netKind  = [ self   currentNetType ];

//    // 属于哪个运营商

//    NSString *carrierName = [UIDevice currentCarrierName];

     // 手机型号

     phoneModel  = [[ UIDevice   currentDevice ]  model ];

     NSLog ( @" 手机型号 : %@" , phoneModel  );

     // 手机系统  +  系统版本号+ app 版本号

     NSDictionary  *infoDictionary = [[ NSBundle   mainBundle ]  infoDictionary ];

     appVersion  = [ NSString   stringWithFormat : @"%@%@ %@" ,[[ UIDevice   currentDevice ]  systemName ],[[ UIDevice   currentDevice ]  systemVersion ],[infoDictionary  objectForKey : @"CFBundleShortVersionString" ]];

     NSLog ( @" 当前 App 版本 :%@" , appVersion );

     dispatch_async ( dispatch_get_main_queue (), ^{

        [ activityView   startAnimating ];

    });

    [[ NSNotificationCenter   defaultCenter ]  postNotificationName : @"SubmitToTheServer"   object : nil ];

}

//获取当前网络类型

-(NSString *)currentNetType

{

    UIApplication *application = [UIApplication sharedApplication];

    NSArray *subviews = [[[application valueForKey:@"statusBar"] valueForKey:@"foregroundView"]subviews];

    NSNumber *dataNetWorkItemView = nil;

    for (id subView in subviews) {

        if ([subView isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {

            dataNetWorkItemView = subView;

            break;

        }

    }

    NSString *networkType = NetworkType_None;

    switch ([[dataNetWorkItemView valueForKey:@"dataNetworkType"] integerValue]) {

        case 0:

            NSLog(@"No wifi or cellular");

            networkType = NetworkType_None;

            break;

        case 1:

            NSLog(@"2G");

            networkType = NetworkType_2G;

            break;

        case 2:

            NSLog(@"3G");

            networkType = NetworkType_3G;

            break;

        case 3:

            NSLog(@"4G");

            networkType = NetworkType_4G;

        default://5

            NSLog(@"Wifi");

            networkType = NetworkType_wifi;

            break;

    }

    return networkType;

}

继续阅读