• ios开发中各种版本、设备的区分


    设备类型的区分-iphone ,ipad-itouch.....
    可以从 UIDevice 的属性 model 得到在现在执行的环境。例子如下:
     
    [cpp] view plaincopyprint?
    
    NSString *modelname = [[UIDevice currentDevice]model];  
    if ([modelname isEqualToString:@"iPhone"]) {  
      // iPhone  
    }  
    if ([modelname isEqualToString:@"IPod Touch"]) {  
      // iPod touch  
    }  
    if ([modelname isEqualToString:@"iPhone Simulator"]) {  
      // iPhone Simulator  
    }  
    
    也可以通过宏定义区分
     
     
    [cpp] view plaincopyprint?
    
    #if TARGET_OS_IPHONE  
        // iPhone Device  
    #endif  
      
    #if TARGET_IPHONE_SIMULATOR  
        // iPhone Simulator  
    #endif  
      
    #if !TARGET_IPHONE_SIMULATOR  
        // iPhone Device  
    #endif  
    ios设备版本的区分-iphone3gs,iphone4....
    ios提供了几种c函数来获得相应信息如下
    [cpp] view plaincopyprint?
    
    struct utsname u;  
    uname(&u); ///-----get device struct info  
    NSString *machine = [NSString stringWithCString:u.machine];  
      
      
    if ([machine isEqualToString:@"iPhone1,1"]) {  
      // iPhone 1G  
    }  
    if ([machine isEqualToString:@"iPhone1,2"]) {  
      // iPhone 3G  
    }  
    if ([machine isEqualToString:@"iPhone2,1"]) {  
      // iPhone 3GS  
    }  
    if ([machine isEqualToString:@"iPod1,1"]) {  
      // iPod touch 1G  
    }  
    if ([machine isEqualToString:@"iPod2,1"]) {  
      // iPod touch 2G  
    }  
    if ([machine isEqualToString:@"iPod3,1"]) {  
      // iPod touch Late2009  
    }  
    
    或者
    [cpp] view plaincopyprint?
    
    - (NSString *) platform  
    {  
      size_t size;  
      sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
      char *machine = malloc(size);  
      sysctlbyname("hw.machine", machine, &size, NULL, 0);///-----get device struct info  
      
        
      NSString *platform = [NSString stringWithCString:machine];  
      
      free(machine);  
      return platform;  
    }  
  • 相关阅读:
    第07组 Beta冲刺 总结
    第07组 Beta冲刺 (5/5)
    第07组 Beta冲刺 (4/5)
    第07组 Beta冲刺 (3/5)
    第07组 Beta冲刺 (2/5)
    第07组 Beta冲刺 (1/5)
    软工实践个人总结
    第03组 Beta冲刺(5/5)
    第03组 Beta冲刺(4/5)
    第03组 Beta冲刺(3/5)
  • 原文地址:https://www.cnblogs.com/jiackyan/p/3210150.html
Copyright © 2020-2023  润新知