How to check iOS version?

后端 未结 30 2466
一生所求
一生所求 2020-11-21 06:37

I want to check if the iOS version of the device is greater than 3.1.3 I tried things like:

[[UIDevice currentDevice].systemVersion         


        
30条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 07:14

    There are version like 7.0 or 6.0.3, so we can simply convert version into numerics to compare. if version is like 7.0, simply append another ".0" to it and then take its numeric value.

     int version;
     NSString* iosVersion=[[UIDevice currentDevice] systemVersion];
     NSArray* components=[iosVersion componentsSeparatedByString:@"."];
     if ([components count]==2) {
        iosVersion=[NSString stringWithFormat:@"%@.0",iosVersion];
    
     }
     iosVersion=[iosVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
     version=[iosVersion integerValue];
    

    For 6.0.0

      if (version==600) {
        // Do something
      }
    

    for 7.0

     if (version==700) {
       // Do something
     }
    

提交回复
热议问题