简体   繁体   English

如何在iOS中获取当前设备和当前平台?

[英]How to get Current Device & Current platform in iOS ?

I am a new developer in iOS Developing. 我是iOS开发中的新开发人员。 I faced a problem on current device. 我在当前设备上遇到问题。 According to requirement i have to design app for all device. 根据要求,我必须为所有设备设计应用程序。 So anybody can help me how to get Current device & current platform of iOS? 那么有人可以帮助我如何获取iOS的当前设备和当前平台吗?

For current device i am using this code: 对于当前设备,我正在使用此代码:

 NSString *deviceType = [[UIDevice currentDevice] model];

My requirement is i have to adjust UITableView row height according to device. 我的要求是我必须根据设备调整UITableView行的高度。

I think you got my question. 我想你有我的问题。 If you need any information please tell me. 如果您需要任何信息,请告诉我。

Thanks in advanced. 提前致谢。

Ok try this one. 好的,尝试这个。

NSString *deviceType = [[UIDevice currentDevice] model]; // for current device

if ([deviceType isEqualToString:@"iPhone"])
{
    NSString *platform = [self platformRawString];
    NSLog(@"platform :%@",platform);
    // To set the half cut in the last cell.

    if ([platform isEqualToString:@"iPhone2,1"])
        //cellHeight = 39.5;
    else if ([platform isEqualToString:@"iPhone4,1"])
        //cellHeight = 42;
    else if ([platform isEqualToString:@"iPhone5,3"] || [platform isEqualToString:@"iPhone5,4"])
        //cellHeight = 42.5;
    else
        //cellHeight = 40.0;
}

Method for getting platform 平台获取方法

- (NSString *)platformRawString
{
  size_t size;
  sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  char *machine = malloc(size);
  sysctlbyname("hw.machine", machine, &size, NULL, 0);
  NSString *platform = [NSString stringWithUTF8String:machine];
  free(machine);
  return platform;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM