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

本文详细介绍了如何从客户端获取并记录数据,并通过网络连接将数据提交至服务器端的过程,包括IMEI号获取、网络类型识别、设备信息收集等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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(kCFAllocatorDefaultcallbackNULL);
    
_CTServerConnectionCopyMobileIdentity(&resultsc, &imei);
    
NSLog (@"IMEI is %@"imei);
    
    
//OpenUDID替代IMEI
    
openUDID = [HXY_OpenUDID value];//导入HXY_OpenUDID文件
    
    
//连接网络类型
    
netKind = [self currentNetType];
    
//    //属于哪个运营商
//    NSString *carrierName = [UIDevice currentCarrierName];
    
    
//手机型号
    
phoneModel = [[UIDevice currentDevicemodel];
    
NSLog(@"手机型号: %@",phoneModel );
    
    
//手机系统 + 系统版本号+app版本号
    
NSDictionary *infoDictionary = [[NSBundle mainBundleinfoDictionary];
    
appVersion = [NSString stringWithFormat:@"%@%@ %@",[[UIDevice currentDevicesystemName],[[UIDevice currentDevicesystemVersion],[infoDictionary objectForKey:@"CFBundleShortVersionString"]];
    
NSLog(@"当前App版本:%@",appVersion);
    
    
dispatch_async(dispatch_get_main_queue(), ^{
        [
activityView startAnimating];

    });

   [[NSNotificationCenter defaultCenterpostNotificationName:@"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;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值